By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

Insert values into MS Access Database table

P: 3
Hello Everyone

I want to insert values into MS Access database through VB.NET in Visual Studio 2005 . I have used the following code which is not working.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=DSA.mdb")
con.Open()
Dim cmd As New OleDb.OleDbCommand("insert into users lname='" & TextBox2.Text & "' and lpwd='" & TextBox3.Text & "'" & "and Username='" & TextBox4.Text, con)

Please help me
May 3 '07 #1
Share this Question
Share on Google+
6 Replies


kenobewan
Expert 2.5K+
P: 4,871
What error message are you receiving? Looks like you don't have your quotations right, suggest you debug. HTH.
May 3 '07 #2

P: 3
What error message are you receiving? Looks like you don't have your quotations right, suggest you debug. HTH.
Thanks for the reply
The error I am facing is "syntax error in INSERT INTO statement"
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=DSA.mdb")
con.Open()
Dim cmd As New OleDb.OleDbCommand("insert into users lname='" & TextBox2.Text & "' and lpwd='" & TextBox3.Text & "'" & "and Username='" & TextBox4.Text, con)


Can U please provide the above statement with correct quotes.

I have even tried
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=E:\Visual Studio 2005\Projects\image\WindowsApplication1\DSA.mdb")
con.Open()
Dim cmd As New OleDb.OleDbCommand("insert into users values '" & TextBox2.Text & "' '" & TextBox3.Text & "' '" & TextBox1.Text, con)
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult)
May 12 '07 #3

P: 1
Dim cmd As New OleDb.OleDbCommand("insert into users(Field names seperated by comma) values( '" & TextBox2.Text & "' '" & TextBox3.Text & "' '" & TextBox1.Text & "' )", con)


You should complete the single quote for the last parameter.
Also specify field names of the table.
May 14 '07 #4

P: 4
Hi Friends
I Am New To Vb.net Pls Help Me Out In For Connecting Msaccess And Sql Databases And Coding For It And Coding For Inserting,deleting,updating,next,previous First And Next Pls
Sep 22 '07 #5

P: 4
how can we able to update ,insert,rows using asp.net.
I am new to dotnet pls help me out pls also specify for oracle and access
Sep 22 '07 #6

P: 3
Dim cmd As New OleDb.OleDbCommand("insert into users(Field names seperated by comma) values( '" & TextBox2.Text & "' '" & TextBox3.Text & "' '" & TextBox1.Text & "' )", con)


You should complete the single quote for the last parameter.
Also specify field names of the table.
Thanks a lot for your response.
I am extremely thankful for your interest in solving my problem.
Nov 15 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.