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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -