c# - 1 button Insert and Update 2 tables -
i have asp.net page button want submit data sql database. i'm trying run insert command on 1 table , update command in table. keep getting error:
incorrect syntax near ','. line 242: cmd.parameters.addwithvalue("@clc", clc); line 243: cmd.parameters.addwithvalue("@rmkc", rmkc); line 244: cmd2.executenonquery(); line 245: } line 246:
i can't seem see why there's issue. maybe there's better way this?
string conn = configurationmanager.connectionstrings["conn"].connectionstring; using (sqlconnection sqlcon = new sqlconnection(conn)) { sqlcon.open(); using (sqlcommand cmd = new sqlcommand()) { cmd.commandtext = "insert tblhistory4 ([tanknum],[hft],[hin]) select @tanknum,@hft,@hin"; cmd.parameters.addwithvalue("@tanknum", tanknum); cmd.parameters.addwithvalue("@hft", hft); cmd.parameters.addwithvalue("@hin", hin); cmd.connection = sqlcon; cmd.executenonquery(); } using (sqlcommand cmd2 = new sqlcommand()) { cmd2.commandtext = "update gpcurrentgauge4 set hft=@hftc,hin=@hinc,hfx=@hfxc tanknumid=@tanknumid"; cmd2.parameters.addwithvalue("@tanknumid", tanknumid); cmd2.parameters.addwithvalue("@hftc", hftc); cmd2.parameters.addwithvalue("@hinc", hinc); cmd2.parameters.addwithvalue("@hfxc", hfxc); cmd2.connection = sqlcon; cmd2.executenonquery(); } } } }
}
Comments
Post a Comment