Read output parameters from a stored procedure using c#

I am trying to read the output parameters from the stored procedure.  There are two of them.

The stored procedure executes correctly.  But, it does not have rows.  

Now, if i drill into the sqlDR and go to
    Non Public Memebers
    Non Public Members
    Inner List
    Then open up both of my output parameters, they both have values, one is a code, and the other is a description.  How can I get those values?
InterfaceExportShipDetails objInterfaceExportShipDetails = (InterfaceExportShipDetails) objInterfaceExport;
            odbcCon.ConnectionString = InterlinkOneDBConnection();

            SqlConnection ObjSQLConn = new SqlConnection();
            ObjSQLConn = InterlinkOneSQLCon(ObjSQLConn);
            SqlDataReader sqlDR;
            for (int i = 0; i <= objInterfaceExportShipDetails.aryStrHandlingID.Length; i++)
                SqlCommand sqlCmd = new SqlCommand("spShipmentImport", ObjSQLConn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@Cost", objInterfaceExportShipDetails.dblPkgCost);
                sqlCmd.Parameters.AddWithValue("@ShipDate", objInterfaceExportShipDetails.dtShipDate);
                sqlCmd.Parameters.AddWithValue("@TrackingNumber", objInterfaceExportShipDetails.aryStrTrackingNumber[i]);
                sqlCmd.Parameters.AddWithValue("@SystemOrderNumber", objInterfaceExportShipDetails.strOrderNumber);
                sqlCmd.Parameters.AddWithValue("@PackageType", objInterfaceExportShipDetails.strPackageType);
                sqlCmd.Parameters.AddWithValue("@PackageID", (i + 1));
                //BWL - 04.23.2010 - status of 0 means to add the shipment detail to the order.
                sqlCmd.Parameters.AddWithValue("@Status", 0);
                sqlCmd.Parameters.AddWithValue("@ShipServiceCode", objInterfaceExportShipDetails.strShipViaCode);
                sqlCmd.Parameters.AddWithValue("@Weight", objInterfaceExportShipDetails.aryStrPkgWeight[i]);
                sqlCmd.Parameters.AddWithValue("@TotalNumberOfPackages", objInterfaceExportShipDetails.aryStrHandlingID.Length);
                //sqlCmd.Parameters.AddWithValue("@ProductCode", DBNull.Value);
                //sqlCmd.Parameters.AddWithValue("@Quantity", DBNull.Value);
                //BWL - 04.23.2010 - adding 999 as the default id, this means remote process.
                sqlCmd.Parameters.AddWithValue("@UpdateRepID", 999);
                sqlCmd.Parameters.AddWithValue("@ShipMethod", "Processed");
                SqlParameter parmReturnCode = sqlCmd.Parameters.Add("@ReturnCode", SqlDbType.Int);
                parmReturnCode.Direction = ParameterDirection.Output;
                SqlParameter parmReturnDesc = sqlCmd.Parameters.Add("@ReturnDesc", SqlDbType.NVarChar, 255);
                parmReturnDesc.Direction = ParameterDirection.Output;
                    objLogging.intSeverity = 1;
                    objLogging.strInterface = "InterlinkOne";
                    objLogging.strEvent = "InterlinkOnePutback";
                    objLogging.strUserID = objInterfaceExportShipDetails.strPSUserID;
                    objLogging.strdeliveryDocNum = objInterfaceExportShipDetails.strOrderNumber;
                    objLogging.strDescription = sqlCmd.CommandText.ToString() + "   " + sqlCmd.Parameters.ToString();
                catch (Exception ex)
                { }
                    sqlDR = sqlCmd.ExecuteReader();
                    while (sqlDR.Read())
                        string strErrorCode = (sqlDR.GetString(0));
                        string strErrorDescription = (sqlDR.GetString(1));

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just read your parameters as fields of your command after your command has been executed.

returnCode = (int)sqlCmd.Parameters["@ReturnCode"].Value;
returnDescription = (int)sqlCmd.Parameters["@ReturnDesc"].Value;

Open in new window

I'm sorry, please ignore the cast to (int) on your return description.

returnDescription = sqlCmd.Parameters["@ReturnDesc"].Value as string;


returnDescription = sqlCmd.Parameters["@ReturnDesc"].Value.ToString();

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bran-DamageAuthor Commented:
I did it a little more like this, but you got me almost there.


                    string strErrorCode = parmReturnCode.Value.ToString();
                    string strErrorDescription = parmReturnDesc.Value.ToString();
Ah very cool. I wasn't sure if that would work. Learned something myself so thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.