c# - SQL statement, OleDbException error INSERT -


there no error in code, no information appearing in database.

        string mysql;         mysql = "insert cars(make,model,price,[image]) values ('"         + tbmake.text + "','" + tbmodel.text + "'," + tbprice.text + ",'" +         fileupload1.filename + "')";         sitedb.insertcommand = mysql;         datalist1.databind(); 

cheers.

with access database word image reserved keyword.
if want use need encapsulate square brakets

"insert cars(make,model,price,[image]) values ......" 

this resolve immediate problem, john skeet pointed out in comment need use parametrized query because solves problem of proper formatting of text values.

what happens handy crafted query if model name (or make) contains single quote?
syntax error waiting (and experience bite when have finished code , ready work)

just complete answer, feel free test if in way adds record db

 mysql = "insert cars(make,model,price,[image]) values (?,?,?,?)";  oledbcommand cmd = new oledbcommand(mysql, con);  cmd.parameters.addwithvalue("@p1", tbmake.text);  cmd.parameters.addwithvalue("@p2", tbmodel.text);  cmd.parameters.addwithvalue("@p3", convert.todecimal(tbprice.text));    cmd.parameters.addwithvalue("@p4", fileupload1.filename);  cmd.executenonquery(); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -