Solved

help with vb.net and ms access database

Posted on 2007-04-01
3
203 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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 …
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…

749 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