c# - SQL Database Updating not working -


i using following code edit function. when enter values not show error not save new values in database . both insert , update commands not not working.

sqlconnection con = new sqlconnection("data source=.\\sqlexpress;attachdbfilename=c:\\users\\omer\\documents\\visual studio 2010\\websites\\wappassignment\\app_data\\loginstuff.mdf;integrated security=true;user instance=true"); sqlcommand cmd; sqldatareader dr;   protected void imgbtnenfn_click(object sender, imageclickeventargs e) {     pnenfn.visible = false;     lblenfn.text = txtenfn.text; }   protected void imgbtnenln_click(object sender, imageclickeventargs e) {     pnenln.visible = false;     lblenln.text = txtenln.text; }  protected void button3_click(object sender, eventargs e) {     con.open();    // cmd = new sqlcommand("update whattypes set [first name]='" + lblenfn.text + "',[last name]='" + lblenln.text + "',[tp number]='" + lblntpn.text + "',email='" + lblenem.text + "',username='" + lblenun.text + "',password='" + lblenp.text + "',userlevel='"+ lbleul.text+"where username='" + txtaeuns.text+"')", con);     cmd = new sqlcommand("insert whattypes([first name], [last name], [tp number], email, username, password, userlevel) values ('" + lblenfn.text + "','" + lblenln.text + "','" + lblntpn.text + "','" + lblenem.text + "', '" + txteun.text + "', '" + lblenp.text + "','" + lbleul.text+"'where username = '"+txtaeuns.text+"' )", con);    cmd.executenonquery();     con.close(); } 

protected void cmdinsert_click(object sender, eventargs e) {     con.open();     string insertquery="insert whattypes([first name], [last name], [tp number], email, username, password, userlevel) "+         " values (@fname,@lname,@tpnumber,@email,@username,@password,@userlevel)";     cmd = new sqlcommand(insertquery,con);     cmd.parameters.addwithvalue("@fname",lblenfn.text);     cmd.parameters.addwithvalue("@lname",lblenln.text);     cmd.parameters.addwithvalue("@tpnumber",lblntpn.text);     cmd.parameters.addwithvalue("@email",lblenem.text);     cmd.parameters.addwithvalue("@username",txteun.text);     cmd.parameters.addwithvalue("@password",lblenp.text);     cmd.parameters.addwithvalue("@userlevel",lbleul.text);     cmd.executenonquery();     con.close(); } protected void cmdupdate_click(object sender, eventargs e) {     con.open();     string insertquery = "update whattypes set [first name]=@fname,[last name]=@lname,"+         "[tp number]=@tpnumber,email=@email,password=@password,userlevel=@userlevel username=@username";     cmd = new sqlcommand(insertquery, con);     cmd.parameters.addwithvalue("@fname", lblenfn.text);     cmd.parameters.addwithvalue("@lname", lblenln.text);     cmd.parameters.addwithvalue("@tpnumber", lblntpn.text);     cmd.parameters.addwithvalue("@email", lblenem.text);     //you not update username     //cmd.parameters.addwithvalue("@username", txteun.text);     cmd.parameters.addwithvalue("@password", lblenp.text);     cmd.parameters.addwithvalue("@userlevel", lbleul.text);     cmd.parameters.addwithvalue("@username", txtaeuns.text);     cmd.executenonquery();     con.close(); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -