What is the wrong with my c# code -
error
server error in '/kibritak3' application.
invalid column name 'name'. invalid column name 'phone'.
description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.
exception details: system.data.sqlclient.sqlexception: invalid column name 'name'. invalid column name 'phone'.
source error:
an unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below.
stack trace:
its come if write code ** if (literal1.text == "data inserted successfully") { response.redirect("http://localhost:1038/kibritak3/companyhomepage.aspx"); } else { txtname.text = ""; txtemail.text = ""; txtphone.text = ""; } ** , without evrything ok ------------------------- full code: public void refress() { txtname.text = ""; txtemail.text = ""; txtphone.text = ""; txtlocation.text = ""; txthistory.text = ""; } protected void imagebutton1_click(object sender, imageclickeventargs e) { sqlcommand cmd = new sqlcommand("insert com_info(name,email,phone,location,history) values('" + txtname.text + "','" + txtemail.text + "','" +txtphone.text+ "','" +txtlocation.text+ "','"+txthistory.text+"')", con); cmd.commandtype = commandtype.text; try { con.open(); cmd.executenonquery(); literal1.text = "data inserted successfully"; con.close(); refress(); } catch (exception ex) { literal1.text = ex.message; } if (literal1.text == "data inserted successfully") { response.redirect("http://localhost:1038/kibritak3/companyhomepage.aspx"); } else { txtname.text = ""; txtemail.text = ""; txtphone.text = ""; } } }
please verify attributes of database once. or not include attributes of table in query.
sqlcommand cmd = new sqlcommand("insert com_info values('" + txtname.text + "','" + txtemail.text + "','" +txtphone.text+ "','" +txtlocation.text+ "','"+txthistory.text+"')", con);
Comments
Post a Comment