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

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -