Query String Example

  • Thread starter Thread starter Patrick.O.Ige
  • Start date Start date
Hello Patrick.O.Ige,

SqlConnection conn = new SqlConnection("yourConnectionString");
SqlCommand cmd = new SqlCommand("SELECT * FROM table where id=@ID", conn);
cmd.Parameters.Add("@ID", Request.QueryString["id"]);
using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
... do something with your data
}
 
Matt said:
Hello Patrick.O.Ige,

SqlConnection conn = new SqlConnection("yourConnectionString");
SqlCommand cmd = new SqlCommand("SELECT * FROM table where id=@ID",
conn); cmd.Parameters.Add("@ID", Request.QueryString["id"]);
using (IDataReader rdr =
cmd.ExecuteReader(CommandBehavior.CloseConnection)) {
.. do something with your data
}

While the code is fine, this approach is a bad idea if the information read
from the database is sensitive. Users can simply probe the database contents
by "walking" ids.

Cheers,
 
Back
Top