c# - Failed to convert from a string to a int32 -


i got problem able retrieve data database on single textbox. want is, want retrieve data of every textboxes database, when tried, getting error:

here code:

string connectionstring = (@"provider=microsoft.ace.oledb.12.0;data source=\archives\projects\program\sell system\sell system\app_data\db1.accdb;persist security info=false;");  private list<list<textbox>> textboxcodecontainer = new list<list<textbox>>(); private list<list<textbox>> textboxquantitycontainer = new list<list<textbox>>(); private list<list<textbox>> textboxdesccontainer = new list<list<textbox>>(); private list<list<textbox>> textboxsubtotalcontainer = new list<list<textbox>>(); private list<list<textbox>> textboxtotalcontainer = new list<list<textbox>>();  private void form1_load(object sender, eventargs e) {       updatetextposition();      oledbdatareader dreader;     oledbconnection conn = new oledbconnection(connectionstring);     conn.open();     oledbcommand cmd = new oledbcommand("select [code] [data]", conn);      dreader = cmd.executereader();      autocompletestringcollection codescollection = new autocompletestringcollection();      while (dreader.read())     {          string numstring = dreader[0].tostring().padleft(4, '0');          codescollection.add(numstring);     }      dreader.close();     conn.close(); }  private void updatedatas() {         oledbdatareader dreader;     oledbconnection conn = new oledbconnection(connectionstring);     conn.open();     oledbcommand cmd = new oledbcommand("select distinct [description], [price] [data] [code]=@code", conn);      cmd.parameters.add("code", system.data.oledb.oledbtype.integer);     cmd.parameters["code"].value = this.textboxcodecontainer[0][0].text;      dreader = cmd.executereader();      while (dreader.read())     {         this.textboxdesccontainer[0][0].text = dreader["description"].tostring();         this.textboxsubtotalcontainer[0][0].text = dreader["price"].tostring();     }      dreader.close();     conn.close(); } 

i tried add:

cmd.parameters.add("code", system.data.oledb.oledbtype.integer); cmd.parameters["code"].value = this.textboxcodecontainer[0][1].text; 

and

while (dreader.read()) {     this.textboxdesccontainer[0][1].text = dreader["description"].tostring();     this.textboxsubtotalcontainer[0][1].text = dreader["price"].tostring(); } 

but got error says: "failed convert parameter value string int32"

try this

you have parse string int32 datatype

cmd.parameters.add("code", system.data.oledb.oledbtype.integer); cmd.parameters["code"].value =int.parse(this.textboxcodecontainer[0][1].text); 

this should work if user enters valid integer

for e.g.

int val=int.parse("45");//works me 

note: not work decimal values

alternatively if price value contains decimal can is

cmd.parameters["code"].value = convert.toint32(convert.todouble(this.textboxcodecontainer[0][1].text)); 

this should work


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -