c# - Struggling to populate datagrid from stored procedure with parameters -
protected datatable retrievealumni2() { { mysqlconnection con = new mysqlconnection("server=100.0.0.0;user id=id;password=pass;database=db;persistsecurityinfo=true"); mysqlcommand cmd = new mysqlcommand("get_alumni_by_city", con); mysqldataadapter da = new mysqldataadapter(cmd); datatable dt = new datatable(); try { string city = textbox1.text; con.open(); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.addwithvalue("@city", sqldbtype.varchar).value = city; da.selectcommand = cmd; cmd.executenonquery(); da.fill(dt); datagridview1.datasource = dt; } catch (system.exception ex) { messagebox.show(ex.message); } { cmd.dispose(); con.close(); } return dt; } } giving error:
"input string not in correct format"
city varchar in mysql server. appreciated.
have tried this?
cmd.parameters.addwithvalue("@city","" + city + "");
Comments
Post a Comment