nishant ranjan

nishant ranjan

  • NA
  • 390
  • 0

error on inserting data into mysql

Aug 3 2013 1:38 AM
table structure
srno               bigint(20)
citycode           bigint(20)
centercode         bigint(20)
rollno             bigint(20)
firstname          varchar(100)
lastname           varchar(100)
fathername         varchar(100)
dob                datetime
gender             char(1)
examdate           datetime
faceimagelocation  varchar(256)
keydata            varchar(256)




string StrQry=Insert into tblstudentDetails ( rollNo,formNo,citycode,firstName,lastName,fatherName,Gender,dob,centerCode,examDate,faceImageLocation,keydata )
 values(  ?rollNo,?formNo,?citycode,?firstName,?lastName,?fatherName,?Gender,?dob,?centerCode,?examDate,?faceImageLocation,?keydata)

SqlCmd = new OdbcCommand(StrQry, SqlCon);
SqlCmd.Parameters.Add(new OdbcParameter("?" + DT.Columns[IntIncVar].ToString(), SqlDbType.Int)).Value = DT.Rows[IntDTCOUNT][IntIncVar];
 SqlCmd.Parameters.Add(new OdbcParameter("?" + DT.Columns[IntIncVar].ToString(), SqlDbType.VarChar)).Value = DT.Rows[IntDTCOUNT][IntIncVar];
SqlCmd.Parameters.Add(new OdbcParameter("?" + DT.Columns[IntIncVar].ToString(), SqlDbType.DateTime)).Value = DT.Rows[IntDTCOUNT][IntIncVar];
...........  //as required
dt is datatable, passing parmeter field wise, i have not written all parameter here, getting right value for each column i.e., getting right value from DT.Rows[IntDTCOUNT][IntIncVar]

SqlCmd.ExecuteNonQuery();
// i am getting error as  "ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.28-rc-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'firstName,'SHREYA CHITNAVIS'lastName,'ABHAY CHITNAVIS'fatherName,'m'Gender,_lati' at line 1"


plz let me know where i am getting wrong

note:- database is mysql



Answers (34)