Solved

vb.net and access adding record.

Posted on 2014-02-01
7
461 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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now