I have done a lot of research and this is what im doing so far (in vb .net 2005)
To create my table in access im using ADOX:
That works wonderfully.
Im using OLEDB to read the data back:
That works great
Im using regular sqlClient to connect to sql2000, not going to display the code as im not having any problem with sql 2000...
Is there an easier way then having to use adox and oledb and sqlclient.net ?
second, my program will have the ability to drop tables. before i pull data from a table i see if it exists using adox: (by the way this is a boolean function)
That works well....
Heres the problem, when I go to open an Access table using oledb, i check to see if it exists using adox. if it doesnt exist, i fire my createdatabase() subroutine (again, it runs at startup if the .mdb file is missing) to rebuild whats missing from the database. it then checks to see if tableexists=false (for every table) before it attempts to build it. the problem lies right before that.
Remember my "dbCatalog.Create(mdbConn)" command that creates the mdb file? I cant use that again when i rerun my createdatabase sub. so i use this
I get this error "Aruguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
so in adox i have to reference an existing db file and all my searches online say i can only do that by opening it with adodb (which i dont want ANOTHER reference.)
I need to be able to Create a DB (adox), Add tables(adox), add records(oledb), drop table(oledb), recreate table if necessary(adox).
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=1089
I thought I could go off this code, but it doesnt work as he wrote it so i cant adapt it.
To create my table in access im using ADOX:
Code:
Dim dbCatalog As ADOX.Catalog = New ADOX.Catalog
Dim dbTable As ADOX.Table
dbCatalog.Create(mdbConn) conn string referenced globally
dbTable = New ADOX.Table
With dbTable
.Name = "Customers"
.Columns.Append("GUID", ADOX.DataTypeEnum.adGUID, 36)
.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "GUID")
.Columns.Append("Company", ADOX.DataTypeEnum.adVarWChar, 255)
End With
dbCatalog.Tables.Append(dbTable)
That works wonderfully.
Im using OLEDB to read the data back:
Code:
cmd = New OleDb.OleDbCommand("SELECT * FROM LastTableUpdate", oLocalConn)
dr = cmd.ExecuteReader
While dr.Read()
msgbox myreader(0)
End While
That works great
Im using regular sqlClient to connect to sql2000, not going to display the code as im not having any problem with sql 2000...
Is there an easier way then having to use adox and oledb and sqlclient.net ?
second, my program will have the ability to drop tables. before i pull data from a table i see if it exists using adox: (by the way this is a boolean function)
Code:
Dim AccessConnection As New System.Data.OleDb.OleDbConnection()
Dim SchemaTable As DataTable
AccessConnection.ConnectionString() = mdbConn
Try
AccessConnection.Open()
Retrieve schema information about Table1.
SchemaTable = AccessConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, strTable})
If SchemaTable.Rows.Count <> 0 Then
MsgBox("Table " & SchemaTable.Rows(0)!TABLE_NAME.ToString & " Exists")
AccessConnection.Close()
Return True
Else
MsgBox("Table does not exist")
AccessConnection.Close()
Return False
End If
Catch ex As Exception
Return False
End Try
That works well....
Heres the problem, when I go to open an Access table using oledb, i check to see if it exists using adox. if it doesnt exist, i fire my createdatabase() subroutine (again, it runs at startup if the .mdb file is missing) to rebuild whats missing from the database. it then checks to see if tableexists=false (for every table) before it attempts to build it. the problem lies right before that.
Remember my "dbCatalog.Create(mdbConn)" command that creates the mdb file? I cant use that again when i rerun my createdatabase sub. so i use this
Code:
If My.Computer.FileSystem.FileExists("datastore.mdb") = False Then
dbCatalog.Create(mdbConn)
Else
dbCatalog.ActiveConnection = mdbConn
End If
I get this error "Aruguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
so in adox i have to reference an existing db file and all my searches online say i can only do that by opening it with adodb (which i dont want ANOTHER reference.)
I need to be able to Create a DB (adox), Add tables(adox), add records(oledb), drop table(oledb), recreate table if necessary(adox).
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=1089
I thought I could go off this code, but it doesnt work as he wrote it so i cant adapt it.
Last edited by a moderator: