Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Stored Procedure return valueStored Procedure return value
Previous
 
Next
New Post
2/10/2011 3:47 PM
 
I have a stored procedure with 6 input parameter and 4 output parameter. In My asp.net – C# code I execute the stored procedure and return the parameter.The stored Procedure execute but the return value is empty. (when I try execute in sql it return data). This is my code.

connection.Close();

}

 

 

 

protected void Button1_Click(object sender, EventArgs e)

 

{

 

 

using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))

 

{

 

 

SqlCommand cmd = new SqlCommand("w_create_order", connection);

 

cmd.CommandType =

 

CommandType.StoredProcedure;

 

 

 

 

 

//input parameters

 

cmd.Parameters.AddWithValue(

 

"@in_order_class", "WEB");

 

cmd.Parameters.AddWithValue(

 

"@in_owner_code", "OP");

 

cmd.Parameters.AddWithValue(

 

"@in_sales_campaign_code", "DEF");

 

cmd.Parameters.AddWithValue(

 

"@in_cus_key", null);

 

cmd.Parameters.AddWithValue(

 

"@in_lab_key", null);

 

cmd.Parameters.AddWithValue(

 

"@in_invoice_number", null);

 

connection.Open();

 

cmd.ExecuteNonQuery();

 

 

//output parameters

 

 

 

//output parameters

 

cmd.Parameters.Add(

 

"@ord_key", SqlDbType.Int, 500);

 

cmd.Parameters[

 

"@ord_key"].Direction = ParameterDirection.Output;

 

 

cmd.Parameters.Add(

 

"@ord_invoice_number", SqlDbType.Int, 500);

 

cmd.Parameters[

 

"@ord_invoice_number"].Direction = ParameterDirection.Output;

 

cmd.Parameters.Add(

 

"@via_ship_via_code", SqlDbType.NVarChar, 500);

 

cmd.Parameters[

 

"@via_ship_via_code"].Direction = ParameterDirection.Output;

 

 

 

string message = (string)cmd.Parameters["@via_ship_via_code"].Value;

 

 

cmd.Parameters.Add(

 

"@ord_ship_after_date", SqlDbType.DateTime);

 

cmd.Parameters[

 

"@ord_ship_after_date"].Direction = ParameterDirection.Output;

 

 

Label1.Text = message;

 

connection.Close();

   

 }

}

 
New Post
2/14/2011 10:04 PM
 
Hi Nikko,

This is due to that you have added output parameters after calling cmd.executenonquery. This is not right. You must add output parameters before executing query on command object. Following is the sequence of calling SP.

  1. Add all the parameters to the command object including output parameters also.
  2. Execute SP.
  3. Fetch value from out put parameters.
This is obvious because at the time query execution. SQL Server engine should be aware with the parameters which carry value out side. . . :)


Thanks & Regards,
Nandip Makwana

DotnetExpertGuide
 
New Post
2/15/2011 5:42 AM
 
Hello tis is very interesting forum and I am looking for such type of forums for getting more knowledge.
 
New Post
2/15/2011 6:27 AM
 
Hello i am new here for the general post.
 
Previous
 
Next
HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Stored Procedure return valueStored Procedure return value


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out