我想用c# 操作一个存储过程。这个存储过程返回3个datatable,我想依次读出这三个datatable,该如何操作

解决方案 »

  1.   

    用一个DataReader来接收
    dr.Next()来换到下一个表
    while(dr.Read())
    {
    //第一个表
    dr["Field"]...dr.Next;
    //第二个表
    }
      

  2.   

    private DataSet MyDataSet()
        {
            //ASP.NET 2.0
            //你想要的是这意思吗?
            string connString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
            SqlConnection conn = new SqlConnection(connString);
            SqlDataAdapter sda = new SqlDataAdapter();
            SqlCommand sc = new SqlCommand();
            sc.CommandText = "存储过程1";
            sc.CommandType = CommandType.StoredProcedure;
            sc.Connection = conn;
            sda.SelectCommand = sc;
            DataSet ds = new DataSet();
            sda.Fill(ds, "Table1");        sc = new SqlCommand();
            sc.CommandText = "存储过程2";
            sc.CommandType = CommandType.StoredProcedure;
            sc.Connection = conn;
            sda.SelectCommand = sc;
            sda.Fill(ds, "Table2");        sc = new SqlCommand();
            sc.CommandText = "存储过程3";
            sc.CommandType = CommandType.StoredProcedure;
            sc.Connection = conn;
            sda.SelectCommand = sc;
            sda.Fill(ds, "Table3");        conn.Close();
            return ds;
        }
      

  3.   

    既然是存储过程,直接用就行了..
    跟用sql语句差不多,只是改下CommandType...至于三个datatable,那是sql语句的事..
      

  4.   

    不好意思让大家误解了。我的意思是,一个sp返回的是3个datatable。怎么把这三个分开来