Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Dear expert.

Need to run 2 stored procedures instead of one in the current program segment, how do you accomplish this

The stored procedures are  1.<B> sp_run</B>

                           2. <B>sp_runu</B>


The program segment is as follows  ::

----------------------------------------------------------------
----------------------------------------------------------------

  protected void btn_Process_Click(object sender, EventArgs e)
        {

            ///LOAN PROCESSING BEGINS
            string str;
            str = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            SqlConnection sqlCon = new SqlConnection(str);


            try
            {
                sqlCon.Open();
             //  SqlCommand SqlCmd = new SqlCommand("sp_ProcessSimpleConvent", sqlCon);
               SqlCommand SqlCmd = new SqlCommand("<B>sp_run</B>", sqlCon);
               SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;


                //Create and supply the output parameters

                SqlCmd.Parameters.AddWithValue("@CMONTH", SqlDbType.Int).Value = txt_Period.Text;
                SqlCmd.Parameters.AddWithValue("@CYEAR", SqlDbType.Int).Value  = txt_Year.Text;



                SqlCmd.Parameters.Add("@RETURN", System.Data.SqlDbType.VarChar, 12);
                SqlCmd.Parameters["@RETURN"].Direction = System.Data.ParameterDirection.Output;

                SqlCmd.ExecuteNonQuery();


                string result = SqlCmd.Parameters["@RETURN"].Value.ToString();

                result = SqlCmd.Parameters["@RETURN"].Value.ToString();

                if (result == "YES")
                {
                    lblStatus.Text = "Loan Processing Done";
                    lblReport.Text = "Loan Processing Done";

                }
                else if (result == "NO")
                {
                    lblStatus.Text = "Loan Processing Aborted";
                    lblReport.Text = "Loan Processing Aborted";
                }

            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.Message;
            }
            finally
            {

Please <B>edit </B>this program such that upon the completion of the first stored procedure
                               <B>1. sp_run</B>

the second stored procedure    <B>2. sp_runu</B> is done.
Posted
Comments
Arasappan 6-Aug-15 3:48am    
what is sp_ProcessSimpleConvent,do u want to remove this sp_ProcessSimpleConvent instead
of sp_run

1 solution

1.Create 2 sqlcommand object with different name
2.assigning the parameter of stored procedure to the respective command objects
3.and execute them separately to get the return values

C#
 sqlCon.Open();
    SqlCommand SqlCmd = new SqlCommand("sp_ProcessSimpleConvent", sqlCon);
     SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
//changed code SqlCmd to  SqlCmd1
     SqlCommand SqlCmd1 = new SqlCommand("sp_run", sqlCon);
     SqlCmd1.CommandType = System.Data.CommandType.StoredProcedure;
 
Share this answer
 
v2
Comments
Arasappan 6-Aug-15 3:50am    
what about the return values of the both procedure..explain that also.
sasanka sekhar panda 6-Aug-15 4:01am    
After passing all the parameter to the respective sqlcommand objects...

SqlCmd.ExecuteNonQuery();
SqlCmd1.ExecuteNonQuery();
string result = SqlCmd.Parameters["@RETURN"].Value.ToString();
string result1 = SqlCmd1.Parameters["@RETURN"].Value.ToString();
sasanka sekhar panda 6-Aug-15 4:02am    
if (result == "YES" && result1 == "YES" )
{
lblStatus.Text = "Loan Processing Done";
lblReport.Text = "Loan Processing Done";

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900