SQL Insert Syntax Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I can't see what is wrong with this statement. I have verfied the table and field names are correct and still have no idea. I am using the following code.
Dim sSQLInsert As String = ("INSERT INTO Members (Member_ID,Password) Values(") & "'" & txtUserName.Value.ToString & "'" & "," & "'" & txtPassword.Value.ToString & "'" & ");"
m_oOleDbCmd.CommandText = ""
m_oOleDbCmd.CommandText = sSQLInsert
m_oOleDbCmd.ExecuteNonQuery

SQL Insert Statement:
"INSERT INTO Members (Member_ID,Password) Values('chrisg','rckrll');"

I compared this to other Insert statements I have that work and don't see anything wrong with it but yet I am getting a syntax error on the Insert statement.
The data types of the fields are Text in an Access .mdb.

Thanks,

Chris
 
Chris Lane said:
Hi,

I can't see what is wrong with this statement. I have verfied the
table and field names are correct and still have no idea. I am using
the following code. Dim sSQLInsert As String = ("INSERT INTO Members
(Member_ID,Password) Values(") & "'" & txtUserName.Value.ToString &
"'" & "," & "'" & txtPassword.Value.ToString & "'" & ");"
m_oOleDbCmd.CommandText = "" m_oOleDbCmd.CommandText = sSQLInsert
m_oOleDbCmd.ExecuteNonQuery

SQL Insert Statement:
"INSERT INTO Members (Member_ID,Password) Values('chrisg','rckrll');"

My first guess would be that Password is a reserved word and you need to
escape it:
"INSERT INTO Members (Member_ID,[Password]) Values('chrisg','rckrll');"

Dim sSQLInsert As String = "INSERT INTO Members (Member_ID,Password)
Values('" & txtUserName.Value.ToString & "','" &
txtPassword.Value.ToString & "');"
 
It looks like Bill has already answered it for you..but I wrote a brief
piece on this and posted some links with all of the Reserved words for
different DB implementations
http://www.knowdotnet.com/articles/reservedwords.html
Chris Lane said:
Hi,

I can't see what is wrong with this statement. I have verfied the table
and field names are correct and still have no idea. I am using the following
code.
Dim sSQLInsert As String = ("INSERT INTO Members (Member_ID,Password)
Values(") & "'" & txtUserName.Value.ToString & "'" & "," & "'" &
txtPassword.Value.ToString & "'" & ");"
m_oOleDbCmd.CommandText = ""
m_oOleDbCmd.CommandText = sSQLInsert
m_oOleDbCmd.ExecuteNonQuery

SQL Insert Statement:
"INSERT INTO Members (Member_ID,Password) Values('chrisg','rckrll');"

I compared this to other Insert statements I have that work and don't see
anything wrong with it but yet I am getting a syntax error on the Insert
statement.
 
Back
Top