Solved

help with vb.net and ms access database

Posted on 2007-04-01
3
169 Views
Last Modified: 2010-04-23
I have a serious brain block going on and I think I have turned this piece of code into one big disaster, I have a couple of variables that I want to insert into an ms access table and I am at a mind block. Below is my code. May be totally wrong, partly correct, not sure. All variables are strings.

Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\emp.mdb;")
cn.Open()
str = "insert into table1 (sid, lname, fname) values(" & ("sid") & ",'" & ("lname") & "','" & ("fname") & "')"
cmd = New OleDbCommand(str, cn)
Cmd.CommandText = str
Cmd.ExecuteNonQuery()

Catch
End Try
cn.Close()

Thank you
0
Comment
Question by:heydude
  • 2
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 18833966
Try this:

str = "insert into table1 (sid, lname, fname) values('" & sid & "','" &  lname  & "','" & fname & "')"
0
 

Author Comment

by:heydude
ID: 18834071
Thank you for you help, that was all I needed.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 18834073
Glad to help :-)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 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

18 Experts available now in Live!

Get 1:1 Help Now