Solved

vb.net and access adding record.

Posted on 2014-02-01
7
466 Views
Last Modified: 2014-02-02
Hi,

Is it possible to connect  vb.net to Microsoft Access  and add a new record entirely by code ?
0
Comment
Question by:lincstech
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:bc10
ID: 39826197
Yes.  The dot net framework data provider supports connection to MS Access using oledb provider as well as ODBC.
0
 
LVL 84
ID: 39826256
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
 

Author Comment

by:lincstech
ID: 39826417
Having problems with the VALUES Section - Error       1      End of statement expected.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 40
ID: 39826662
Could be anything. No way to tell without seeing the code,
0
 

Author Comment

by:lincstech
ID: 39826762
            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
 
LVL 84
ID: 39827599
You have this:

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

It should look something like this:

cmd.CommandText = "INSERT blah blah"
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39827896
And you have a missing concatenation  right after VALUES.

VALUES('"me.title.text & "

should bb

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

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question