Asp.net 如何获取在执行过程时创建的表的值?

Asp.net 如何获取在执行过程时创建的表的值?,asp.net,Asp.net,SQL Server中的过程 ALTER procedure [dbo].[staffscorecard] @STAFF_ID INT = NULL, @countexel int output,-- Explicitly declare output variables to fetch these values @scoreexel int output, @countgood int output,-- Explicitly declare output

SQL Server中的过程

ALTER procedure [dbo].[staffscorecard] 
    @STAFF_ID INT = NULL,
    @countexel int output,-- Explicitly declare output variables to fetch these values
    @scoreexel int output,
    @countgood int output,-- Explicitly declare output variables to fetch these values
    @scoregood int output,
    @countaverage int output,
    @scoreaverage int output,
    @countbelowaverage int output,
    @scorebelowaverage int output,
    @countpoor int output,
    @scorepoor int output
as 
Begin 
    select 
        @countexel = count(STAFF_ID) 
    from 
        TbStudentSurvey 
    where 
        FEEDBACK = 'excellent' 
        and STAFF_ID = ISNULL(@STAFF_ID, STAFF_ID)
    select 
        @countgood = count(STAFF_ID) 
    from 
        TbStudentSurvey 
    where 
        FEEDBACK = 'good' 
        and STAFF_ID = ISNULL(@STAFF_ID, STAFF_ID)

    select 
        @scoreexel = Score  
    from 
        TbStaffScoreMaster 
    where 
        Status = 'Excellent' 
    select 
        @scoregood = Score  
    from 
        TbStaffScoreMaster 
    where 
        Status = 'Good' 
    select 
        @countaverage = count(STAFF_ID) 
    from 
        TbStudentSurvey 
    where 
        FEEDBACK = 'average' 
        and STAFF_ID = ISNULL(@STAFF_ID, STAFF_ID)
          select 
      @scoreaverage = Score  
    from 
        TbStaffScoreMaster 
    where 
        Status = 'Average' 
     select 
        @countbelowaverage = count(STAFF_ID) 
    from 
        TbStudentSurvey 
    where 
        FEEDBACK = 'belowaverage' 
        and STAFF_ID = ISNULL(@STAFF_ID, STAFF_ID)
    select 
      @scorebelowaverage = Score  
    from 
        TbStaffScoreMaster 
    where 
        Status = 'Belowaverage' 
    select 
        @countpoor = count(STAFF_ID) 
    from 
        TbStudentSurvey 
    where 
        FEEDBACK = 'poor' 
        and STAFF_ID = ISNULL(@STAFF_ID, STAFF_ID)
         select 
       @scorepoor= Score  
    from 
        TbStaffScoreMaster 
    where 
        Status = 'Poor' 


End


GO
用于在表单中获取值的代码

if (Page.IsValid)
{
    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MET"].ConnectionString))
    {
        SqlCommand cmd = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd1 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd2 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd3 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd4 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd5 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd6 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd7 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd8 = new SqlCommand("staffscorecard", conn);
      SqlCommand cmd9 = new SqlCommand("staffscorecard", conn);

        cmd.CommandType = CommandType.StoredProcedure;
        cmd1.CommandType = CommandType.StoredProcedure;
        cmd2.CommandType = CommandType.StoredProcedure;
        cmd3.CommandType = CommandType.StoredProcedure;
        cmd4.CommandType = CommandType.StoredProcedure;
        cmd5.CommandType = CommandType.StoredProcedure;
        cmd6.CommandType = CommandType.StoredProcedure;
        cmd7.CommandType = CommandType.StoredProcedure;
        cmd8.CommandType = CommandType.StoredProcedure;
        cmd9.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd1.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd2.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd3.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd4.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd5.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd6.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd7.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd8.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
      cmd9.Parameters.AddWithValue("STAFF_ID", ddlstaffname.Text);
        SqlParameter count1 = cmd.Parameters.Add("@countexel", SqlDbType.Int);
        count1.Direction = ParameterDirection.Output;
        SqlParameter count2 = cmd1.Parameters.Add("@countgood", SqlDbType.Int);
        count2.Direction = ParameterDirection.Output;
        SqlParameter count3 = cmd2.Parameters.Add(" @scoreexel", SqlDbType.Int);
        count3.Direction = ParameterDirection.Output;
        SqlParameter count4 = cmd3.Parameters.Add("@scoregood", SqlDbType.Int);
        count4.Direction = ParameterDirection.Output;
        SqlParameter count5 = cmd4.Parameters.Add("@countaverage", SqlDbType.Int);
        count5.Direction = ParameterDirection.Output;
        SqlParameter excvalue = cmd5.Parameters.Add("@scoreaverage", SqlDbType.Int);
        excvalue.Direction = ParameterDirection.Output;
        SqlParameter goodvalue = cmd6.Parameters.Add("@countbelowaverage", SqlDbType.Int);
        goodvalue.Direction = ParameterDirection.Output;
        SqlParameter avgvalue = cmd7.Parameters.Add("@scorebelowaverage", SqlDbType.Int);
        avgvalue.Direction = ParameterDirection.Output;
        SqlParameter belowavgvalue = cmd8.Parameters.Add("@countpoor", SqlDbType.Int);
        belowavgvalue.Direction = ParameterDirection.Output;
        SqlParameter poorvlue = cmd9.Parameters.Add("@scorepoor", SqlDbType.Int);
        poorvlue.Direction = ParameterDirection.Output;
        //cmd.CommandType = CommandType.StoredProcedure;
        //cmd.Parameters.Add("@countexecel",SqlDbType.Int).Value=




        //  conn.Open();

         cmd.ExecuteNonQuery();
         cmd1.ExecuteNonQuery();
         cmd2.ExecuteNonQuery();
         cmd3.ExecuteNonQuery();
         cmd4.ExecuteNonQuery();
         cmd5.ExecuteNonQuery();
         cmd6.ExecuteNonQuery();
         cmd7.ExecuteNonQuery();
         cmd8.ExecuteNonQuery();
         cmd9.ExecuteNonQuery();



         int countexcel = (int)count1.Value;
         int good = (int)count2.Value;
         int avg = (int)count3.Value;
         int belowavg = (int)count4.Value;
         int poor = (int)count5.Value;
         int excelvalue = (int)excvalue.Value;
         int gudvalue = (int)goodvalue.Value;
         int avgevalue = (int)avgvalue.Value;
         int bloavgvalue = (int)belowavgvalue.Value;
         int poorvalue = (int)poorvlue.Value;

如果要读回数据-不要使用
ExecuteNonQuery
-这是用于像
INSERT
DELETE
这样不返回数据结果的命令!您需要了解如何将
SqlDataReader
ExecuteReader()结合使用
holy code克隆蝙蝠侠!