我必须将ASP经典系统转换为C#
我有一个存储过程,最多可以返回7个记录集(取决于传入的参数)。
我需要知道如何简单地将所有记录集作为单独的DataTables返回,以便我可以遍历其中的所有内容,直到结束时才跳到下一个DataTable,而不必运行多个SQL语句和使用多个适配器。填充语句以将每个表添加到数据集中。
在经典情况下,当我到达循环的结尾以移至下一条语句时,使用objRS.NextRecordset()进行了一个简单的Do While not objRS.EOF循环。
我可以使用不需要完全重写当前后端代码的任何东西吗?
每个记录集具有不同数量的列和行。它们彼此无关。我们从Stored Proc返回多个记录集以减少流量。
例子会很好。
谢谢
SqlConnection con=new SqlConnection("YourConnection String");
SqlCommand cmd=new SqlCommand();
SqlDataAdapter da=new SqlDataAdapter();
DataSet ds = new DataSet();
cmd = new SqlCommand("name of your Stored Procedure", con);
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue("@SuperID", id);//if you have parameters.
da = new SqlDataAdapter(cmd);
da.Fill(ds);
con.Close();
之后,您可以使用以下不同的(7)个记录集:
ds.Tables[0]
ds.Tables[1]
ds.Tables[2]
ds.Tables[3]
ds.Tables[4]
ds.Tables[5]
ds.Tables[6]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句