views:

146

answers:

4

I am working with ASP.NET and SQL Server 2005.

I know how to create a stored proceudre but i do not know what to place in a stored procedure when i need to make use of a QueryString.

My SQL Statement in CODE =

"SELECT * FROM TableName WHERE ID = '" + Request.QueryString("ID") + "'"

Now what must i place in my stored procedure to get this to work? I want to call a stored procedure and thus do not want to use this code in my code behind.

Thanks in advanced!

+1  A: 

Create an sqlcommand object

set the commandtext = "StoredProcName"

add an sqlParameter with the name of your sproc parameter - set its type

set its value to Request.QueryString("ID")

check this out for full instructions:

http://support.microsoft.com/kb/306574

Paul
+1  A: 

Try the following code:

SqlCommand mycommand = new SqlCommand("yourstoredproc", con);
mycommand.CommandType = CommandType.StoredProcedure;
mycommand.Parameters.AddWithValue("@yourparam", Request.QueryString["ID"]);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = mycommand;
DataSet dataset = new DataSet();
adapter.Fill(dataset);
Himadri
A: 
SqlCommand cmd = new SqlCommand("storedprocedure_name",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@parameter_of-procedure",Request.QueryString"ID"]);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = mycommand;
DataSet dataset = new DataSet();
adapter.Fill(dataset);


//using sqldatareader
SqlCommand cmd = new SqlCommand("yourstoredproc", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@parameters_of_procedure",Request.QueryString["ID"]);
con.open()
sqldatareader dr=cmd.executereader();
gridview1.datasouce=dr;
gridview1.databind();
con.close();
maxy
Hi, i am not using a gridview, i am populating text boxes
Etienne
A: 

The answer for this problem is located here

Etienne