473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Error Creating Table in ADOX

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
Nov 21 '05 #1
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
////
Nov 21 '05 #2
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
////

Nov 21 '05 #3
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
////

Nov 21 '05 #4
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)
Nov 21 '05 #5
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)

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
3
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...
2
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...
6
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...
4
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...
4
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...
10
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...
3
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.