Jason

Jason

  • NA
  • 1
  • 0

Inserting Into Access

Apr 6 2007 12:23 AM

I’m new to VB and I have an Access database that I’m trying to insert records into using VB.NET.  For some reason, I’m getting an error telling me that I have a syntax error in my INSERT INTO statement.  Here is the code I’m using:

 

Dim SQL As String

SQL = "INSERT INTO tblUser (EmpFirstName, EmpLastName, UserName, Password) VALUES ('firstname', 'lastname', 'username', 'password')"

Try

Dim MyConnection As New OleDbConnection(ConnectionString)

Dim MyCommand As New OleDbCommand(SQL, MyConnection)

MyConnection.Open()

MyCommand.ExecuteNonQuery()

MyConnection.Close()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

 

I have the connection string stored in a variable named ConnectionString (not just a fancy name) in a module, and I know the connection string is good because I use it in other parts of the program and they work flawlessly.  Here is a link to the actual error message that pops up.  Click Here. 

 

Some of the suggestions that I’ve tried and haven’t worked are:

-    Adding a ; after the SQL statement like this: 'password';)"

-    Adding a ; after the ) like this: ‘password’);”

-    Changing the ‘ to ‘’ (double apostrophe)

 

Any ideas would be greatly appreciated,

 

Thanks!


Answers (1)