lincstech
asked on
vb.net and access adding record.
Hi,
Is it possible to connect vb.net to Microsoft Access and add a new record entirely by code ?
Is it possible to connect vb.net to Microsoft Access and add a new record entirely by code ?
Yes. The dot net framework data provider supports connection to MS Access using oledb provider as well as ODBC.
If all you're doing is adding a record, you can do this:
Dim con As New OLEDB.OLEDBConnection
con.ConnectionString = "ConnectionString"
con.Open
Dim cmd As New OLEDB.OLEDBCommand
cmd.Connection = con
cmd.CommandText = "INSERT INTO MyTable(Col1, Col2, Col3) VALUES('" Me.txCol1 & "','" & Me.txControl2 & "','" & Me.txControl5 & "')"
cmd.ExecuteNonQuery
You can get lots of examples of connection strings at www.connectionstrings.com
ASKER
Having problems with the VALUES Section - Error 1 End of statement expected.
Could be anything. No way to tell without seeing the code,
ASKER
cmd.CommandText = cmd.CommandText = "INSERT INTO Contacts(title, FirstName, LastName, Address1, Address2, Address3, City, County, PostCode, Phone, Mobile, Email, Notes) VALUES('"me.title.text & "','" & Me.firstname.text & "','" & Me.last.text & "','" & address1.text & "','" & Address2.text & "','" & Address3.text & "','" & city.text & "','" & county.text & "','" & postcode.text & "','" & phone.text & "','" & mobile.text & "','" & email.text & "','" & notes.text "')"
It's just that line which is causing problems.
You have this:
cmd.commandtext = cmd.commandtext = "INSERT blah blah"
It should look something like this:
cmd.CommandText = "INSERT blah blah"
cmd.commandtext = cmd.commandtext = "INSERT blah blah"
It should look something like this:
cmd.CommandText = "INSERT blah blah"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.