c# - ado.net can't read from my database -


this noob-problem im tearing hair soon. i'm trying read local database gives me nothing. here code:

protected void readbtn2_click(object sender, eventargs e) {     string connstring = "server=localhost; trusted_connection=yes; database=expreimentaldb";      string sqlstring  = ("select * tblcity city = '@city'");      using (sqlconnection conn = new sqlconnection(connstring))     {         using (sqlcommand cmd = new sqlcommand(sqlstring, conn))         {             cmd.commandtype = commandtype.text;             cmd.parameters.addwithvalue("city", citytb.text);              conn.open();             using (sqldatareader reader = cmd.executereader())             {                 gridview1.datasource = reader;                 gridview1.databind();             }         }     } } 

the connectionstring should work (because if rename database part in string crashes).

the sql working (tried in sql manager)

reader (the sqldatareader) empty havnt tried out yet?

you need remove single quotes around @city in query becomes

string sqlstring  = "select * tblcity city = @city"; 

and

cmd.parameters.addwithvalue("city", citytb.text); 

needs changed

cmd.parameters.addwithvalue("@city", citytb.text); 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -