Ken Carter Ken Carter - 1 month ago 7
ASP.NET (C#) Question

Session variable as a SqlParameter

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

cmd.Parameters["@CAssetID"].Value.ToString();


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.Parameters["@CAssetID"].Value.ToString();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = RejectConnecton;

RejectConnecton.Open();
reader = cmd.ExecuteReader();
RejectConnecton.Close();


Thanks for any help you can offer!

Answer
cmd.Parameters.AddWithValue("@CAssetID", Session["YourSessionParamName"]);