• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

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 ?
0
lincstech
Asked:
lincstech
  • 2
  • 2
  • 2
  • +1
1 Solution
 
bc10Commented:
Yes.  The dot net framework data provider supports connection to MS Access using oledb provider as well as ODBC.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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

Open in new window

You can get lots of examples of connection strings at www.connectionstrings.com
0
 
lincstechAuthor Commented:
Having problems with the VALUES Section - Error       1      End of statement expected.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Jacques Bourgeois (James Burger)PresidentCommented:
Could be anything. No way to tell without seeing the code,
0
 
lincstechAuthor Commented:
            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 "')" 

Open in new window


It's just that line which is causing problems.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You have this:

cmd.commandtext = cmd.commandtext = "INSERT blah blah"

It should look something like this:

cmd.CommandText = "INSERT blah blah"
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
And you have a missing concatenation  right after VALUES.

VALUES('"me.title.text & "

should bb

VALUES('" & me.title.text & "
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now