c# - Data type mismatch in criteria expression Oledb Access database -


i'm getting error:

data type mismatch in criteria expression

when using code. , using access database.

oledbconnection bab = new oledbconnection();  bab.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\sdega\onedrive\school\werknemersdata.accdb;persist security info=false;";  bab.open(); try {                       oledbcommand kaas = new oledbcommand();      kaas.connection = bab;     kaas.commandtext = "insert werknemersdata (naam, adres, postcode, woonplaats, salaris) values ('" + txtnaam.text + "', '" + txtadress.text + "', '" + txtpostcode1.text + " " +txtpostcode2.text + "', '" + txtwoonplaats.text + "', '" + txtsalaris.text + "')  ";     kaas.executenonquery(); // goes wrong      txtstatus.backcolor = color.green;      messagebox.show("data saved");      bab.close();  } catch (exception ghakbal) {     messagebox.show("error" + ghakbal); } 

you missed 1 ' after '" + txtpostcode1.text + " , 1 before " +txtpostcode2.text + "' , 1 , between them. should this:

'" + txtpostcode1.text + "' , '" +txtpostcode2.text + "', 

also recommend use parameterized queries avoid sql injection. this:

kaas.commandtext = "insert werknemersdata (naam, adres, postcode, woonplaats, salaris) values (?, ? ,....."); kaas.parameters.addwithvalue("naam", txtnaam.text); kaas.parameters.addwithvalue("adres", txtadress.text); //and other parameters... 

also better specify type directly , use value property. read more here.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -