c# - Invalid input - format string ASP.NET -
hello i'm quite new in asp.net programming
dropdownlist code:
protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) { sqlconnection test = new sqlconnection("data source=michaŁ-komputer;initial catalog=projektnet_s10772;integrated security=true"); sqlcommand com; string str; test.open(); str = "select * klient klient_id='" + dropdownlist1.text.trim() + "'"; com = new sqlcommand(str, test); sqldatareader reader = com.executereader(); if (reader.read()) { txtimie2.text = reader["imie"].tostring(); txtnazwisko2.text = reader["nazwisko"].tostring(); txtemail2.text = reader["adres_email"].tostring(); txttelefon2.text = reader["telefon"].tostring(); txtmiasto2.text = reader["miasto"].tostring(); reader.close(); test.close(); } }
update code
protected void btnedytuj1_click(object sender, eventargs e) { sqlconnection edytuj = new sqlconnection("data source=michaŁ-komputer;initial catalog=projektnet_s10772;integrated security=true"); { sqlcommand cmd = new sqlcommand("update klient set imie='"+txtimie2.text+"', nazwisko='"+txtnazwisko+"', adres_email='"+txtemail2+"', telefon='"+txttelefon2+"', miasto='"+txtmiasto2+"' klient_id='"+convert.toint32 (txtmiasto2.text).tostring()+"'", edytuj); edytuj.open(); cmd.executenonquery(); edytuj.close(); gridview3.databind(); } }
what i'm trying do: i'm trying update grindview form ( using txtboxes located outside of grindview form ) dropdownlist list working expected (fullfiling textboxes date grindview ) - update buttton isn't. when i'm running updated code form i'm getting
invalid input - format string
row 141: sqlcommand cmd = new sqlcommand("update klient set imie='" +txtimie2.text+"', nazwisko='"+txtnazwisko+"', adres_email='"+txtemail2+"', telefon='" +txttelefon2+"', miasto='"+txtmiasto2 +"' klient_id='"+convert.toint32 (txtmiasto2.text).tostring()+"'", edytuj);
could try me? thank
you should work on code:
using (sqlconnection edytuj = new sqlconnection("data source=michaŁ-komputer;initial catalog=projektnet_s10772;integrated security=true")) using (sqlcommand cmd = new sqlcommand("update klient set imie=@imie, nazwisko=@nazwisko, adres_email=@email, telefon=@telefon, miasto=@miasto klient_id=@id", edytuj)) { cmd.parameters.addwithvalue("@imie", txtimie2.text); cmd.parameters.addwithvalue("@nazwisko", txtnazwisko.text); cmd.parameters.addwithvalue("@email", txtemail2.text); cmd.parameters.addwithvalue("@telefon", txttelefon2.text); cmd.parameters.addwithvalue("@miasto", txtmiasto2.text); cmd.parameters.addwithvalue("@id", ""); //set proper id cmd.executenonquery(); gridview3.databind(); }
Comments
Post a Comment