选择按钮后,运行2个存储过程而不是1 [英] Run 2 stored procedures instead of 1 after selecting the button

查看:60
本文介绍了选择按钮后,运行2个存储过程而不是1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

1.创建具有不同名称的2个sqlcommand对象

2.分配存储的参数对各个命令对象的过程

3.并单独执行它们以获得返回值



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

 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;


这篇关于选择按钮后,运行2个存储过程而不是1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆