asp.net - Query string in SQL command c# -


first of all.. excuse me bad english , hope understood.

i'm regullar work linq , sql new me.

i'm trying next thing: have next method on c#:

public string nicemethod()  {      sqlconnection connection = new sqlconnection("data source=*******;integrated security=false;");      string commandtext = "select bla items main = 1";      sqlcommand command = new sqlcommand(commandtext, connection);      connection.open();      string tdate = (string)command.executescalar();      connection.close();      return tdate;  } 

i have page example: items.aspx?nid=144

how can select command querystring , take value

from "items" table id (nid) show on address ?

the table have design example:id, title, bla, main.

try this:

int nid = int.parse(request.querystring["nid"].tostring()); nicemethod(nid);  public string nicemethod(int nid)  {     using (var conn = new sqlconnection("data source=server;initial catalog=blah;integrated security=false;"))    using (var cmd = conn.createcommand())    {         conn.open();         cmd.commandtext = @"select bla, id, title items main = @nid";          cmd.parameters.addwithvalue("@nid", nid);         string tdate = cmd.executescalar().tostring();                      return tdate;    }  } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -