c# - Getting error due to column name of my database table is "from" -
my database column name "from" getting error while change column name other name error not occuring.why?
protected void button1_click(object sender, eventargs e) { sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["mycon"].connectionstring); con.open(); string qry="insert mynew(name,age,from,address,job)values(@name,@age,@from,@address,@job)"; sqlcommand cmd= new sqlcommand(qry, con); cmd.parameters.addwithvalue("@name", textbox1.text); cmd.parameters.addwithvalue("@age", textbox2.text); cmd.parameters.addwithvalue("@from",textbox3.text); cmd.parameters.addwithvalue("@address", textbox4.text); cmd.parameters.addwithvalue("@job", textbox5.text); cmd.executenonquery(); con.close(); }
when change column name city not getting error why happening?
from
reserved keyword in sql. if want use table name, have escape by:
- putting between backticks (mysql , others)
- putting between square brackets (ms access, sql server)
so either
insert mynew(name,age,`from`,address,job)values(@name,@age,@from,@address,@job)
or
insert mynew(name,age,[from],address,job)values(@name,@age,@from,@address,@job)
depending on database you're using.
to avoid confusion, it's better use different column name.
Comments
Post a Comment