c# - Int to string - Saving back to a database from a textbox -


i saving values textbox database. how save number entered in textbox database. have tried following error saying input string not in correct format

newcarsrow.customerid = convert.toint32(textbox5.text); //i have tried newcarsrow.customerid = int.parse(textbox5.text); 

i saving text entered textbox so

newcarsrow.surname = textbox1.text.tostring(); 

instead of using

newcarsrow.customerid = int.parse(textbox5.text); 

you should try using

int customerid = 0; if(int.tryparse(textbox5.text.trim(), out customerid)) {   newcarsrow.customerid = customerid; } else {   // customer id received text box not valid int. relevant error processing } 

now wont exception facing, , able perform relevant error handling.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -