为什么没有处理int Result=100;
        string area_code = Session["area_code"].ToString();
        string userid=Session["userid"].ToString()  ;
        string connectionString = GetSection1("vehicleConnectionString");
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand com = new SqlCommand("sp_check_bank_bill", connection);
            com.CommandType = CommandType.StoredProcedure;
            SqlParameter p1 = com.Parameters.Add("@area", SqlDbType.VarChar,10);
            p1.Value = area_code;
            SqlParameter p2 = com.Parameters.Add("@telecomm_account", SqlDbType.VarChar, 30);
            p2.Value = telecomm_account.Text;
            SqlParameter p3 = com.Parameters.Add("@bill_yearmonth", SqlDbType.VarChar, 20);
            p3.Value = Bill_yearmonth.Text;
            SqlParameter p4 = com.Parameters.Add("@employee", SqlDbType.VarChar, 20);
            p4.Value = userid;
            SqlParameter p5 = com.Parameters.Add("@pos_telecomm_account", SqlDbType.VarChar, 30);
            p5.Value = Pos_account.Text;
            connection.Open();
            //SqlDataReader reader = com.ExecuteReader();
            //if (reader.Read())
            //     Result = reader.GetInt16(0);
            Result = com.ExecuteNonQuery();
        }
        switch (Result)
        {
            case 100:
                Status.Text = "警告:存储过程调用异常,稽核处理没有执行!";
                break;
            case 0:
                Status.Text="稽核处理完成!";
                break;
            case -1:
                Status.Text = "警告:这个月份的账单已经归档,不能在处理了!";
                break;
            case -2:
                Status.Text = "警告:银行账单中pos费用和pos账单中费用不匹配";
                break;        }返回值总是-1,表里面查询也没处理痕迹

解决方案 »

  1.   

    你的存储过程呢?com.ExecuteNonQuery(); 这个方法是返回影响行数,要是你的存储过程只是简单的查询,还不是进行修改,删除操作的话,那返回值当然是-1咯!
      

  2.   

    ExecuteNonQuery(); 
    是得到影响的行数,比如插入,删除,修改等,如果是查询则始终是-1;
    用SqlDataAdapter获取数据集吧!
      

  3.   

    Result = com.ExecuteNonQuery(); 大哥,这是在干吗??你是要获得存储过程里的输出参数吗?
    如果是的话,那就不是这么写的,不然偶也不知道你要干吗了SqlParameter a = theCommand2.Parameters.Add("@code", SqlDbType.VarChar, 15);
                    a.Direction = ParameterDirection.Output;
                    theConn.Open();
                    int i = theCommand2.ExecuteNonQuery();
                    theConn.Close();
                    return a.Value.ToString();上面的是获得输出参数的方法
      

  4.   

    一方面我的存储过程有个小问题,一方面确实需要设置输出参数,不过写法略有不同,不过还是要感谢ximi82878
      int Result=100;
            string area_code = Session["area_code"].ToString();
            string userid=Session["userid"].ToString()  ;
            string connectionString = GetSection1("vehicleConnectionString");
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
               // SqlCommand com = new SqlCommand("sp_check_bank_bill", connection);
                 SqlCommand com = new SqlCommand("sp_check_bank_bill", connection);
                com.CommandType = CommandType.StoredProcedure;
                SqlParameter p1 = com.Parameters.Add("@area", SqlDbType.VarChar, 10);
                p1.Value = area_code;
                SqlParameter p2 = com.Parameters.Add("@telecomm_account", SqlDbType.VarChar, 30);
                p2.Value = telecomm_account.Text;
                SqlParameter p3 = com.Parameters.Add("@bill_yearmonth", SqlDbType.VarChar, 20);
                p3.Value = Bill_yearmonth.Text;
                SqlParameter p4 = com.Parameters.Add("@employee", SqlDbType.VarChar, 20);
                p4.Value = userid;
                SqlParameter p5 = com.Parameters.Add("@pos_telecomm_account", SqlDbType.VarChar, 30);
                p5.Value = Pos_account.Text;
                p1.Direction = ParameterDirection.Input;
                p2.Direction = ParameterDirection.Input;
                p3.Direction = ParameterDirection.Input;
                p4.Direction = ParameterDirection.Input;
                p5.Direction = ParameterDirection.Input;
                SqlParameter p_out = com.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 1);
                p_out.Direction = ParameterDirection.ReturnValue;
                connection.Open();
                //SqlDataReader reader = com.ExecuteReader();
                //if (reader.Read())
                //     Result = reader.GetInt16(0);
                com.CommandTimeout = 3000;
                com.ExecuteNonQuery();
                Result = (int)p_out.Value;
            }
            switch (Result)
            {
                case 100:
                    Status.Text = "警告:存储过程调用异常,稽核处理没有执行!";
                    break;
                case 0:
                    Status.Text="稽核处理完成!";
                    break;
                case -1:
                    Status.Text = "警告:这个月份的账单已经归档,不能在处理了!";
                    break;
                case -2:
                    Status.Text = "警告:银行账单中pos费用和pos账单中费用不匹配";
                    break;
                case -3:
                    Status.Text = "警告:没有这个月份的账单!";
                    break;
            }