Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net and access adding record.

Posted on 2014-02-01
7
Medium Priority
?
473 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

705 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