C# Syntax Error in INSERT INTO statement C# -
if (txtusername.text != "") { string q = "insert info(username) values ('" + txtusername.text.tostring() + "')"; dosomething(q); txtusername.text = ""; } else { messagebox.show("please complete neccessary information"); } if (txtpassword.text != "") { string = "insert info(password) values ('" + txtpassword.text.tostring() + "')"; dosomething(a); txtusername.text = ""; } else { messagebox.show("please complete neccessary information"); } private void dosomething(string q) { try { cn.open(); cmd.commandtext = q; cmd.executenonquery(); cn.close(); } catch (exception e) { cn.close(); messagebox.show(e.message.tostring()); } }
every time run show error. dont know how fix it. code should record data put in textbox ms access database. plz helpp
presumably, you've initialized cn somewhere doing like
cn = new sqlconnection();
you need pass connection string database constructor:
cn = new sqlconnection("your connection string here");
or set sometime later, before connect:
cn.connectionstring = "your connection string here";
Comments
Post a Comment