Exception: Syntax error in INSERT INTO statement

Sep 16 2007 3:35 PM

Hello,

I just spendfew long hours trying to understand why I got this exception.

This is my code:

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;"

         + "Data Source=D:\\PlayerRegistered.mdb";

string strSQL = "INSERT INTO Players"+

         "(FirstName,LastName,User,Code)"+

         "VALUES('"+TextBox1.Text.ToString()+"','"

                  +TextBox2.Text.ToString()+"','"

                  +TextBox3.Text.ToString()+"','"

                  +TextBox4.Text.ToString()+"')";

OleDbConnection myConn = new OleDbConnection(strDSN);

OleDbCommand myCmd = new OleDbCommand(strSQL,myConn);

try

{

      myConn.Open();

      myCmd.ExecuteNonQuery();

}

catch (Exception exp)

{

      Console.WriteLine("Error:{0}", exp.Message);

}

myConn.Close();

I checked my syntax  dozens of times and I couldn't found nothing wrong  in it.

can somone please help me???


Answers (5)