c# - SQL Syntax error when trying to insert array values of a Datatable -



c# - SQL Syntax error when trying to insert array values of a Datatable -

i having sql syntax error when seek insert in mysql database array values of datatable named 'table'.

error [42000] [mysql][odbc 3.51 driver][mysqld-5.0.27-community-nt]you have error in sql syntax; check manual corresponds mysql server version right.

datatable = table;

here's code:

(int x = 0; x < table.rows.count; x++) { conn.open(); odbccommand command = new odbccommand("insert jevslimporttemp(jevslimporttempcode, jevslimporttempdescription, jevslimporttempamount)values('" + table.rows[x][0].tostring() + "','" + table.rows[x][1].tostring() + "','" + convert.todouble(table.rows[x][2].tostring()) + "');", conn); command.executenonquery(); conn.close(); }

you have values in variable interfering sql, single quote or question mark. should parameterize query.

odbccommand command = new odbccommand("insert jevslimporttemp(jevslimporttempcode, jevslimporttempdescription, jevslimporttempamount)values(?, ?, ?);", conn); command.parameters.addwithvalue("jevslimporttempcode", table.rows[x][1].tostring()); command.parameters.addwithvalue("jevslimporttempdescription", table.rows[x][1].tostring()); command.parameters.addwithvalue("jevslimporttempamount", convert.todouble(table.rows[x][2].tostring()));

c# mysql sql datatable

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -