c# - How to insert Data into sql server database -
i'm trying insert data sql server 2014 database, error
incorrect syntax near ')'.
my table matches types of data put in, example, i'm put int
int
.
here code:
string ip = request.userhostaddress; string name = "jesus said: love enemies (v.s.)"; int blueq = convert.toint32(textbox1.text); int redq = convert.toint32(textbox2.text); int whiteq = convert.toint32(textbox3.text); int blackq = convert.toint32(textbox4.text); int whiteqr = convert.toint32(textbox9.text); int redqr = convert.toint32(textbox10.text); int sn = 600; int price = total_jslye; string size; if (radiobutton1.checked == false) { size = "11x35"; } else size = "18x50"; try { string conn = system.configuration.configurationmanager.connectionstrings["sqlcs"].connectionstring; var cmd = "insert cartsigns (@signnumber, @redquantity, @bluequantity, @whitequantity, @blackquantity, @whitereflectivequantity, @redreflectivequantity, @size, @signname, @ipaddress, @price)"; using (sqlconnection com = new sqlconnection(conn)) { using (sqlcommand cmds = new sqlcommand(cmd, com)) { cmds.parameters.addwithvalue("@signnumber", sn); cmds.parameters.addwithvalue("@redquantity", redq); cmds.parameters.addwithvalue("@bluequantity", blueq); cmds.parameters.addwithvalue("@whitequantity", whiteq); cmds.parameters.addwithvalue("@blackquantity", blackq); cmds.parameters.addwithvalue("@whitereflectivequantity", whiteqr); cmds.parameters.addwithvalue("@redreflectivequantity", redqr); cmds.parameters.addwithvalue("@size", size); cmds.parameters.addwithvalue("@signname", name); cmds.parameters.addwithvalue("@ipaddress", ip); cmds.parameters.addwithvalue("@price", price); com.open(); cmds.executenonquery(); } } }
so please help, thanks
your parameter names can not have brackets or spaces in them in sql server. rename them @signnumber, @redquantity, @bluequantity... etc.
Comments
Post a Comment