Question

i have a problem with receiving value of output parameter when i execute stored procedure using SqlCommand. I don't have problem with output parameter when i execute stored procedure not from C# code, but from SQL Server Management Studio. Here is fragment of my C# code:

    rest = -1;
    XmlDocument res = new XmlDocument();
    res.LoadXml("<Result><ErrCode>0</ErrCode></Result>");
    using (SqlCommand sqlCmd = Params.SqlCn.CreateCommand())
    {
    sqlCmd.CommandType = CommandType.StoredProcedure;
    sqlCmd.CommandText = "dbo.wss_doProductAdd_sp";
    sqlCmd.Parameters.Clear();
    sqlCmd.Parameters.Add(new SqlParameter("@quantity", ilosc));
    sqlCmd.Parameters.Add(new SqlParameter("@addToLog", addToLog));
    sqlCmd.Parameters.AddWithValue("@rest", rest).Direction =           ParameterDirection.Output;
    XmlReader xr = sqlCmd.ExecuteXmlReader();
    XmlNode newNode = res.ReadNode(xr);
    while (newNode != null)
    {
    res.DocumentElement.AppendChild(newNode);
    newNode = res.ReadNode(xr);
    }
    xr.Close();
    Params.SqlCn.Close();

I've found this: Problem reading out parameter from stored procedure using c# I added a line that closes reader but it didn't helped. And some user from the link above uses LoadHits method, and i cannot find it in MSDN or in Google.

Was it helpful?

Solution

Since my comment solved your problem, I thought I'd add it as an answer:

I don't see where you're trying to read the parameter. Have you actually checked sqlCmd.Parameters[2].Value after you execute the query to see its value?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top