Connecting to an Access database (MDB)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I use ADO.NET to connect to a mdb database? I have not been able to find
anything on this.

Also, I am trying to use ADO in VB.NET and for some reason I can't seem to
get a command to work.

The code is below
Imports System.Data.Odbc
Imports System.Data
Imports System.Data.OleDb


Dim oODBCConnection As OdbcConnection
Dim sConnString As String = Masterconn
oODBCConnection = New Odbc.OdbcConnectio(sConnString)

Dim cmdUpdateDB As New ADODB.Command

With cmdUpdateDB
.ActiveConnection.ConnectionString =
oODBCConnection.ConnectionString
.CommandType = ADODB.CommandTypeEnum.adCmdText
.CommandText = "Insert into tbl_Songs (title) values ('" &
txtNewSong.Text & "')"
.Execute()
End With

I know the connection string is good because I use it to connect to the
database and load data into a recordset.

ANy ideas?
 
Użytkownik "Dacuna said:
Can I use ADO.NET to connect to a mdb database? I have not been able to
find
anything on this.

Also, I am trying to use ADO in VB.NET and for some reason I can't seem to
get a command to work.

The code is below
Imports System.Data.Odbc
Imports System.Data
Imports System.Data.OleDb


Dim oODBCConnection As OdbcConnection
Dim sConnString As String = Masterconn
oODBCConnection = New Odbc.OdbcConnectio(sConnString)

Dim cmdUpdateDB As New ADODB.Command

Some off topic: why import System.Data.OleDb if you use old ADO (not
ADO.NET)? And why don't you use ADO.NET?

Regards,
Grzegorz
 
Użytkownik "Dacuna said:
Can I use ADO.NET to connect to a mdb database? I have not been able to
find
anything on this.

Also, I am trying to use ADO in VB.NET and for some reason I can't seem to
get a command to work.

The code is below
Imports System.Data.Odbc
Imports System.Data
Imports System.Data.OleDb


Dim oODBCConnection As OdbcConnection
Dim sConnString As String = Masterconn
oODBCConnection = New Odbc.OdbcConnectio(sConnString)

Dim cmdUpdateDB As New ADODB.Command

Why you want to use ADODB.Command? In ADO.Net you should use OleDbCommand
(for OleDb provider).
In my opinion, If you want to use old ADO (and ADODB Command) you must
import ADODB namespace (and add reference to suitable Com object).

Regards,
Grzegorz
 
Użytkownik "Dacuna said:
Can I use ADO.NET to connect to a mdb database? I have not been able to
find
anything on this.

Also, I am trying to use ADO in VB.NET and for some reason I can't seem to
get a command to work.

The code is below
Imports System.Data.Odbc
Imports System.Data
Imports System.Data.OleDb


Dim oODBCConnection As OdbcConnection
Dim sConnString As String = Masterconn
oODBCConnection = New Odbc.OdbcConnectio(sConnString)

Dim cmdUpdateDB As New ADODB.Command

Why do you want to use ADODB.Command? In ADO.Net you should use OleDbCommand
(for OleDb provider).
However, If you want to use old ADO (and ADODB Command) you must
import ADODB namespace (and add reference to suitable COM library).

Regards,
Grzegorz
 
The reason that I did not go with ADO.NET is that I'm not very familiar with
it.

I basically need normal database related commands such as add, edit and
delete records. I have found some documentation at

http://support.microsoft.com/kb/821765/EN-US/

but the thing is that the update code expects you to provide a row number.
Well, if I have a table that is being update constantly I have no idea. What
I thought I would do is edit the data adapter's sql statement and fill the
dataset with the following code. The table in the database is number 1 so
that is why I added the number 1

With OleDbDataAdapter1
..SelectCommand.CommandText = "select * from tbl_instruments where
instname='" & txtNewInst.Text & "'"
..Fill(DataSet11, 1)
End With

I know I'm probably using the objects correctly because it should not be thi
scomplicated.

Any ideas?
 
Back
Top