Solved

vb.net and access adding record.

Posted on 2014-02-01
7
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85
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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
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 85
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

635 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