Friday 15 February 2013

c# - "Input String was not in a correct format" - Why? -



c# - "Input String was not in a correct format" - Why? -

i error:

input string not in right format.

from code shown below. want delete row in database click on button.

sqlconnection conn = new sqlconnection(@"datasource=.\sqlexpress; attachdbfilename=c:\users\mr\documents\student.mdf; integrated security=true;connect timeout=30;user instance=true"); sqlcommand cmd = new sqlcommand(); int x = convert.toint32(table2datagridview.selectedcells[0].value); cmd.parameters.clear(); cmd.connection = con; cmd.commandtext = "delete table2 name=@n"; cmd.parameters.addwithvalue("@n", x); con.open(); cmd.executenonquery(); con.close(); messagebox.show("removed");

i error on first line.

@n first textbox can set name on that.

replace

int x = convert.toint32(table2datagridview.selectedcells[0].value);

with

string x = table2datagridview.selectedcells[0].value.tostring();

query should work this.

c# string input sql-server-express

No comments:

Post a Comment