troubleshooting Question

unable to retrieve output parameter sql 2008

Avatar of Codingitup
Codingitup asked on
C#
3 Comments1 Solution341 ViewsLast Modified:
Hi All,

I've got the below code that populates a dataset but has an output parameter as well. When it does to set the variable with the output parameter I get the error message: -

Object reference not set to an instance of an object.

            dt = new DataTable();
            MakeDataTable();
            SqlConnection conn = new SqlConnection("Data Source=*************)      conn.Open();
            SqlCommand cmd = new SqlCommand("Get_QuestionList", conn);
            SqlDataReader dr = null;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@SerialNo", txtSerialNo.Text));
            cmd.Parameters.Add(new SqlParameter("@StageID", 820));
            cmd.Parameters.Add(new SqlParameter("@MfgRoute", "MTO"));

            SqlParameter parm2 = new SqlParameter("@ErrReturn", SqlDbType.VarChar);
            parm2.Size = 255;
            parm2.Direction = ParameterDirection.Output; // This is important! 
            cmd.Parameters.Add(parm2);
            
            SqlParameter parm3 = new SqlParameter("@LoggedPartNo", SqlDbType.VarChar);
            parm3.Size = 255;
            parm3.Direction = ParameterDirection.Output; // This is important! 
            cmd.Parameters.Add(parm3);


            dr = cmd.ExecuteReader();

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

            if (dr.HasRows  == false )
            {
                MessageBox.Show("This product is not setup for prompted inspection as no questions have been assigned. Please contact your administrator");
                QuestionsFound = false;
                txtSerialNo.Text = "";
                return;
            }

What am I doing please?

Best Regards
Lee
ASKER CERTIFIED SOLUTION
sachinpatil10d

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros