Hurb
asked on
Connect to MS Access db
This question has probably been asked a hundred times, but what the heck...
I want to connect to a MS Access DB;
filename="MsgTaker.mdb"; tableName="Msgs"; Coloums="MsgID,MsgFor,MsgF rom,....."
I want to add the data from the textboxes to the db using coding because the user won't be viewing the data just adding to the db.
So I am looking for your help to connect to the database then table and datset and whatever needed cause I'm quite new to VB.NET.
I want to do all this by coding. Please include any references that have to be added.
Thanks
P.S. I would prefer not to use SQL if that matter, probably JET or something instead.
I want to connect to a MS Access DB;
filename="MsgTaker.mdb"; tableName="Msgs"; Coloums="MsgID,MsgFor,MsgF
I want to add the data from the textboxes to the db using coding because the user won't be viewing the data just adding to the db.
So I am looking for your help to connect to the database then table and datset and whatever needed cause I'm quite new to VB.NET.
I want to do all this by coding. Please include any references that have to be added.
Thanks
P.S. I would prefer not to use SQL if that matter, probably JET or something instead.
ASKER
How do i go about getting the connectionString? Probably a Basic Question but sorry.
What about datasets and all that crap.
What about datasets and all that crap.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If all you're doing is adding records to the database, you can do this directly, without datasets/datareaders/dataa dapters/et c. You just need a connection and the SQL string to tell the server (i.e. the Access database) what to do...
For Access databases, the connection string looks like this
"Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=C:\path\databaseNam e.mdb"
Note that this is not a password protected database in this example.
For Access databases, the connection string looks like this
"Provider=Microsoft.Jet.OL
Note that this is not a password protected database in this example.
ASKER
Chaosian,
What Sub do i call to add to the database then.
What Sub do i call to add to the database then.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What reference do i have to add cause:
Type 'oledbConnection' is not defined.
Type 'oledbCommand' is not defined.
Type 'oledbConnection' is not defined.
Type 'oledbCommand' is not defined.
you need to add the line Imports System.Data.OleDb (or something close to this -- intellisense will let you know) at the beginning of the class, before the class declaration....see the very first thing I posted (#1 in the first response to your post).
Imports System.Data.Oledb
Public Class MyClass
etc
etc
Imports System.Data.Oledb
Public Class MyClass
etc
etc
ASKER
Just more errors, is there a reference i must add like from the project menu, add reference.
Could you check your solution explorer for the references that you have there please.
Thanks again.
Could you check your solution explorer for the references that you have there please.
Thanks again.
All the references are in my code above
Reference System.Data
2. The addition must be done using a SQL INSERT statement to add new records (UPDATE to update an existing record).
3. Your code needs to look something like this:
Dim conn AsoledbConnection = New OLEDBConnection(connection
conn.open
Dim cmd As oledbCommand = "INSERT INTO tableName(columnA,columnB,
cmd.ExecuteNonQuery
cmd.Dispose()
conn.Close()
You need to list the values to insert in exaclty the order that the columns are listed. Autonumber columns do not need to be listed. Also, ensure that all mandatory fields have values provided.