asp.net - invalid column name sql drop down list -


i'm creating drop down list populated data online database; however, every time run it keeps giving me error message

"invalid column 'first name' ".

i have tried putting space between , still doesn't work. column name on database 'first name'. please advise.

sqlcommand cmd = new sqlcommand("select extnumber, firstname, lastname extensions", con);             con.open();             cmd.executereader();             dropdownlist1.datasource = cmd.executereader();             dropdownlist1.datatextfield = "first name";             dropdownlist1.datavaluefield = "ext number";             dropdownlist1.databind(); 

my friend, ideea if have spaces in column names, must enclosed in [] brackets.

so, code must changed this:

sqlcommand cmd = new sqlcommand("select [ext number], [first name], lastname       extensions", con);         con.open();         cmd.executereader();         dropdownlist1.datasource = cmd.executereader();         dropdownlist1.datatextfield = "first name";         dropdownlist1.datavaluefield = "ext number";         dropdownlist1.databind();  

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -