473,746 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CreateADOUnitsT able(ByVal sTablename As String)

Dim oDB As ADOX.Catalog

Dim oUnits As ADOX.Table

oUnits = New ADOX.Table

oDB = New ADOX.Catalog

oDB.ActiveConne ction = myConn

With oUnits

..Name = sTablename

..Columns.Appen d("UnitName", ADOX.DataTypeEn um.adVarWChar, 20)

..Columns.Appen d("Class", ADOX.DataTypeEn um.adVarWChar, 5)

..Columns.Appen d("Comments", ADOX.DataTypeEn um.adVarWChar, 35)

End With

oDB.Tables.Appe nd(oUnits) '<=== Error occurs here

oUnits = Nothing

oDB = Nothing

End Sub
Nov 21 '05 #1
5 2078
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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create ("Provider=Micr osoft.Jet.OLEDB .4.0;" & "Data
Source=C:\db1.m db")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;" &
_
" Data Source=C:\db1.m db;User Id=admin;Passwo rd=;")
Dim cmd As New OleDb.OleDbComm and("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.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
Exit Sub
End Try
cmd = New OleDb.OleDbComm and("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
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**********@p lanet.nl> wrote in message
news:uN******** ******@tk2msftn gp13.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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create ("Provider=Micr osoft.Jet.OLEDB .4.0;" & "Data
Source=C:\db1.m db")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;" & _
" Data Source=C:\db1.m db;User Id=admin;Passwo rd=;")
Dim cmd As New OleDb.OleDbComm and("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.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
Exit Sub
End Try
cmd = New OleDb.OleDbComm and("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
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**********@p lanet.nl> wrote in message
news:uN******** ******@tk2msftn gp13.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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create ("Provider=Micr osoft.Jet.OLEDB .4.0;" & "Data
Source=C:\db1.m db")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;" & _
" Data Source=C:\db1.m db;User Id=admin;Passwo rd=;")
Dim cmd As New OleDb.OleDbComm and("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.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
Exit Sub
End Try
cmd = New OleDb.OleDbComm and("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
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 CreateADOUnitsT able(ByVal sTablename As String)
¤
¤ Dim oDB As ADOX.Catalog
¤
¤ Dim oUnits As ADOX.Table
¤
¤ oUnits = New ADOX.Table
¤
¤ oDB = New ADOX.Catalog
¤
¤ oDB.ActiveConne ction = myConn
¤
¤ With oUnits
¤
¤ .Name = sTablename

You may need to add here the following line of code:

..ParentCatalog = oDB

¤
¤ .Columns.Append ("UnitName", ADOX.DataTypeEn um.adVarWChar, 20)
¤
¤ .Columns.Append ("Class", ADOX.DataTypeEn um.adVarWChar, 5)
¤
¤ .Columns.Append ("Comments", ADOX.DataTypeEn um.adVarWChar, 35)
¤
¤ End With
¤
¤ oDB.Tables.Appe nd(oUnits) '<=== Error occurs here
¤
¤
¤
¤ oUnits = Nothing
¤
¤ oDB = Nothing
¤
¤ End Sub
¤

Paul ~~~ pc******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #5
Thanks Paul, I'll try that.

Wayne

"Paul Clement" <Us************ ***********@sws pectrum.com> wrote in message
news:cq******** *************** *********@4ax.c om...
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 CreateADOUnitsT able(ByVal sTablename As String)
¤
¤ Dim oDB As ADOX.Catalog
¤
¤ Dim oUnits As ADOX.Table
¤
¤ oUnits = New ADOX.Table
¤
¤ oDB = New ADOX.Catalog
¤
¤ oDB.ActiveConne ction = myConn
¤
¤ With oUnits
¤
¤ .Name = sTablename

You may need to add here the following line of code:

.ParentCatalog = oDB

¤
¤ .Columns.Append ("UnitName", ADOX.DataTypeEn um.adVarWChar, 20)
¤
¤ .Columns.Append ("Class", ADOX.DataTypeEn um.adVarWChar, 5)
¤
¤ .Columns.Append ("Comments", ADOX.DataTypeEn um.adVarWChar, 35)
¤
¤ End With
¤
¤ oDB.Tables.Appe nd(oUnits) '<=== Error occurs here
¤
¤
¤
¤ oUnits = Nothing
¤
¤ oDB = Nothing
¤
¤ End Sub
¤

Paul ~~~ pc******@amerit ech.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
7281
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 save an array in an Excel .XLS format?
3
10179
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 to the point where I want to add the new view to the views collection. I get Runtime error 3001 which is telling me "Arguments are of wrong type,are out of acceptable range or conflict with one another"
2
6122
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 (specifically a left outer join). I'm including the code that creates the relationships with the inner join. Any help or suggestions would be greatly appreciated. Thanks! <----- CODE FOLLOWS ----->
6
2704
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 is YES, but after creating the new table DEP2005, this property change to NO. It means it won't allow zero lenght.. How can I change this property in C#?
4
8127
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 Access DB and then add a Linked Table pointing to the table on the SQL Server and then run an "Insert Into (linked table)" query to add the new rows. I am having a problem getting the syntax to add that linked table to my local Access DB. When I...
4
23906
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 populate a combo with this information? Then, once this value is selected, how can I populate other combos with the column names of the selected table? Thanks,
10
2957
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 must I use to create an autonumbering field? 3. Which datatype must I use to create an OLE-object field? I'm currently using Microsoft ActiveX Data Objects Library 2.8 and using engine type 5.
3
2658
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. Writing to a table (tblRandom) the values from the recordset. -------------------------------- Private Sub append_record_Click() Dim strSQL As String Dim dotsql As String
3
4927
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 ADODB.Connection objADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database\abc.mdb;User Id=admin;Password=;") objCatalog = New ADOX.Catalog objCatalog.ActiveConnection = objADOConnection ...
0
9516
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9351
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9286
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8229
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6774
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6062
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2200
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.