0

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!

5
  • you have not added ["@CAssetID"] to cmd. you should add it Commented Nov 7, 2016 at 17:31
  • What session variable? There's no session variable there. You're converting the value of a parameter (that isn't there) to a string and discarding it. What session variable? Commented Nov 7, 2016 at 17:31
  • This line does nothing: cmd.Parameters["@CAssetID"].Value.ToString(); is that where you're trying to set the value? Commented Nov 7, 2016 at 17:31
  • This might help. stackoverflow.com/questions/11867729/… Commented Nov 7, 2016 at 17:32
  • 2
    Change cmd.Parameters["@CAssetID"].Value.ToString(); to cmd.Parameters.Add(new SqlParameter("@CAssetID", Session["MySessionVar"])); - may need a little tweaking based on your session variable. Commented Nov 7, 2016 at 17:33

1 Answer 1

2
cmd.Parameters.AddWithValue("@CAssetID", Session["YourSessionParamName"]);
Sign up to request clarification or add additional context in comments.

1 Comment

The exact final code was:......cmd.Parameters.AddWithValue("@CAssetID",Session["CAssetID"]); Thanks to all for the responses and mybirthname nailing it. I could have sworn I was there before but I must have had something crosseyed. Works perfect!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.