I am getting an error that "object no longer valid" at the point indicated
in the code below - I am trying to build a table in an Access 2000 database
using ADOX. Any thoughts on what might cause this?
==================== code =================
Sub CreateADOUnitsTable(ByVal sTablename As String)
Dim oDB As ADOX.Catalog
Dim oUnits As ADOX.Table
oUnits = New ADOX.Table
oDB = New ADOX.Catalog
oDB.ActiveConnection = myConn
With oUnits
..Name = sTablename
..Columns.Append("UnitName", ADOX.DataTypeEnum.adVarWChar, 20)
..Columns.Append("Class", ADOX.DataTypeEnum.adVarWChar, 5)
..Columns.Append("Comments", ADOX.DataTypeEnum.adVarWChar, 35)
End With
oDB.Tables.Append(oUnits) '<=== Error occurs here
oUnits = Nothing
oDB = Nothing
End Sub 5 2050
Wayne,
When I do this using classic Ado I get forever all kind of ISO errors.
I make only the database with ADO and go than directly to ADONET.
Here a sample (more complete than the previous),
I hope that helps?
Cor
\\\needs that ADOX 2.7 lib for etc.
Public Class Main
Public Shared Sub Main()
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\db1.mdb")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" &
_
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class
////
Cor;
Thanks for that information. I'll try to adapt that to my project.
Wayne
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uN**************@tk2msftngp13.phx.gbl... Wayne,
When I do this using classic Ado I get forever all kind of ISO errors.
I make only the database with ADO and go than directly to ADONET.
Here a sample (more complete than the previous),
I hope that helps?
Cor
\\\needs that ADOX 2.7 lib for etc. Public Class Main Public Shared Sub Main() Dim catNewDB As New ADOX.Catalog Dim fi As New IO.FileInfo("c:\db1.mdb") If fi.Exists Then If MessageBox.Show("Delete?", "Existing File db1.mdb", _ MessageBoxButtons.YesNo) = DialogResult.Yes Then fi.Delete() Else Exit Sub End If End If catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=C:\db1.mdb") 'To make tables we use Adonet Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;"
& _ " Data Source=C:\db1.mdb;User Id=admin;Password=;") Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _ "AutoId int identity ," & _ "Id int NOT NULL," & _ "Name NVarchar(50)," & _ "BirthDate datetime," & _ "IdCountry int," & _ "CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn) conn.Open() Try cmd.ExecuteNonQuery() Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "OleDbException") Exit Sub Catch ex As Exception MessageBox.Show(ex.Message, "GeneralException") Exit Sub End Try cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _ "AutoId int identity ," & _ "Id int NOT NULL," & _ "Name NVarchar(50)," & _ "CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn) Try cmd.ExecuteNonQuery() Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "OleDbException") Exit Sub Catch ex As Exception MessageBox.Show(ex.Message, "GeneralException") Exit Sub End Try conn.Close() End Sub End Class ////
Cor;
You were correct, that works much more reliably. Thanks for the education.
Wayne
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uN**************@tk2msftngp13.phx.gbl... Wayne,
When I do this using classic Ado I get forever all kind of ISO errors.
I make only the database with ADO and go than directly to ADONET.
Here a sample (more complete than the previous),
I hope that helps?
Cor
\\\needs that ADOX 2.7 lib for etc. Public Class Main Public Shared Sub Main() Dim catNewDB As New ADOX.Catalog Dim fi As New IO.FileInfo("c:\db1.mdb") If fi.Exists Then If MessageBox.Show("Delete?", "Existing File db1.mdb", _ MessageBoxButtons.YesNo) = DialogResult.Yes Then fi.Delete() Else Exit Sub End If End If catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=C:\db1.mdb") 'To make tables we use Adonet Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;"
& _ " Data Source=C:\db1.mdb;User Id=admin;Password=;") Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _ "AutoId int identity ," & _ "Id int NOT NULL," & _ "Name NVarchar(50)," & _ "BirthDate datetime," & _ "IdCountry int," & _ "CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn) conn.Open() Try cmd.ExecuteNonQuery() Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "OleDbException") Exit Sub Catch ex As Exception MessageBox.Show(ex.Message, "GeneralException") Exit Sub End Try cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _ "AutoId int identity ," & _ "Id int NOT NULL," & _ "Name NVarchar(50)," & _ "CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn) Try cmd.ExecuteNonQuery() Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "OleDbException") Exit Sub Catch ex As Exception MessageBox.Show(ex.Message, "GeneralException") Exit Sub End Try conn.Close() End Sub End Class ////
On Fri, 20 Aug 2004 05:58:26 -0600, "Wayne Wengert" <wa***************@wengert.com> wrote:
¤ I am getting an error that "object no longer valid" at the point indicated
¤ in the code below - I am trying to build a table in an Access 2000 database
¤ using ADOX. Any thoughts on what might cause this?
¤
¤ ==================== code =================
¤ Sub CreateADOUnitsTable(ByVal sTablename As String)
¤
¤ Dim oDB As ADOX.Catalog
¤
¤ Dim oUnits As ADOX.Table
¤
¤ oUnits = New ADOX.Table
¤
¤ oDB = New ADOX.Catalog
¤
¤ oDB.ActiveConnection = myConn
¤
¤ With oUnits
¤
¤ .Name = sTablename
You may need to add here the following line of code:
..ParentCatalog = oDB
¤
¤ .Columns.Append("UnitName", ADOX.DataTypeEnum.adVarWChar, 20)
¤
¤ .Columns.Append("Class", ADOX.DataTypeEnum.adVarWChar, 5)
¤
¤ .Columns.Append("Comments", ADOX.DataTypeEnum.adVarWChar, 35)
¤
¤ End With
¤
¤ oDB.Tables.Append(oUnits) '<=== Error occurs here
¤
¤
¤
¤ oUnits = Nothing
¤
¤ oDB = Nothing
¤
¤ End Sub
¤
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Thanks Paul, I'll try that.
Wayne
"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:cq********************************@4ax.com... On Fri, 20 Aug 2004 05:58:26 -0600, "Wayne Wengert"
<wa***************@wengert.com> wrote: ¤ I am getting an error that "object no longer valid" at the point
indicated ¤ in the code below - I am trying to build a table in an Access 2000
database ¤ using ADOX. Any thoughts on what might cause this? ¤ ¤ ==================== code ================= ¤ Sub CreateADOUnitsTable(ByVal sTablename As String) ¤ ¤ Dim oDB As ADOX.Catalog ¤ ¤ Dim oUnits As ADOX.Table ¤ ¤ oUnits = New ADOX.Table ¤ ¤ oDB = New ADOX.Catalog ¤ ¤ oDB.ActiveConnection = myConn ¤ ¤ With oUnits ¤ ¤ .Name = sTablename
You may need to add here the following line of code:
.ParentCatalog = oDB
¤ ¤ .Columns.Append("UnitName", ADOX.DataTypeEnum.adVarWChar, 20) ¤ ¤ .Columns.Append("Class", ADOX.DataTypeEnum.adVarWChar, 5) ¤ ¤ .Columns.Append("Comments", ADOX.DataTypeEnum.adVarWChar, 35) ¤ ¤ End With ¤ ¤ oDB.Tables.Append(oUnits) '<=== Error occurs here ¤ ¤ ¤ ¤ oUnits = Nothing ¤ ¤ oDB = Nothing ¤ ¤ End Sub ¤
Paul ~~~ pc******@ameritech.net Microsoft MVP (Visual Basic) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JBAdamsJr |
last post by:
I want to be able to create an Excel file with a VB.NET program on a server that does not have Microsoft Excel loaded on it. I am using the Jet OLE DB to read other data files. Can this be used to...
|
by: KemperR |
last post by:
Hello Experts outhere,
may be someone can tell me whats going wrong with my ADOX trial.
I have an Access 2002 database with some tables and queries (views)
The code listed below works well up...
|
by: Gandalf |
last post by:
I'm creating relationships between tables using VBA and ADOX. I can
create one-to-one relationships with an inner join, but I can't figure
out how to create these relationships with an outer join...
|
by: Claudia Fong |
last post by:
Hello,
I'm using the sql statement below to create a new table from an old one.
But I found a little problem with that.
In my old table DEP2004, I have one field's property allow zero length...
|
by: Wayne Wengert |
last post by:
I am trying to create a VB.NET Windows application to move some data from a
local Access DB table to a table in a SQL Server. The approach I am trying
is to open an OLEDB connection to the local...
|
by: Steven Smith |
last post by:
Hello all,
I have a vb6 (not .NET) program using MS Access as the backend. As part of
an import form, I need to allow the user to select the table containing the
data to be imported. How can I...
|
by: C# Beginner |
last post by:
Hi there,
I'm currently trying to create a MS access file at runtime, but I stumble
into some problems.
1. When I use Datatype adUnsignedInt I get an error (invalid type).
2. Which datatype...
|
by: Bhavsan |
last post by:
Here is what I am trying to do. Kindly, help me.
1. I'm creating a query dynamically based on User input using VBA
(strSQL and DotSQL in the code below)
2. Executing the created query with in VBA...
|
by: Vee007 |
last post by:
Following is my code:
Dim objCatalog As ADOX.Catalog
Dim objTableLink As ADOX.Table
Dim objADOConnection As ADODB.Connection
Try
objADOConnection = New...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |