Ken Carter Ken Carter - 1 year ago 100
ASP.NET (C#) Question

Session variable as a SqlParameter

I've got this all except for my...


Line of code where I am trying to assign the session variable to SqlParameter to pass it in to a stored procedure. I just can't seem to get the syntax right. I've tried several different things here is my last attempt.

SqlConnection RejectConnecton = new SqlConnection("Data Source=GBAPTCCSR01;Initial Catalog=CInTracDB;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "usp_RejectSubmission";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = RejectConnecton;

reader = cmd.ExecuteReader();

Thanks for any help you can offer!

Answer Source
cmd.Parameters.AddWithValue("@CAssetID", Session["YourSessionParamName"]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download