从存储过程在C#中返回的多个记录 [英] Return multiple recordsets from stored proc in C#
问题描述
我有一个经典的ASP系统转换为C#
我有一个存储过程,最多可以返回记录集7(根据传入的参数)。
我需要知道我可以简单地返回所有的记录集作为单独的数据表,这样我可以通过循环无论是有的,跳到下一个数据表,当我到达它的结束,而不必运行多个SQL语句和使用多adapter.Fill语句每个表添加到DataSet。
在经典,这是一个简单的待办事项虽然不是objRS.EOF循环使用objRS.NextRecordset(),当我到了循环的结尾移动到下一条语句。
有什么我可以使用,不需要当前后端code总重写?
每个记录具有不同数目的列和行的。它们彼此无关。我们回到从存储过程的多个记录,以减少交通。
例子就好了。
感谢
的SqlConnection CON =新的SqlConnection(YourConnection字符串);
CMD的SqlCommand =新的SqlCommand();
SqlDataAdapter的大=新的SqlDataAdapter();
DataSet的DS =新的DataSet();
CMD =新的SqlCommand(你的存储过程的名称,CON);
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue(\"@SuperID,身份证); //如果有参数。
DA =新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]
I am having to convert an ASP classic system to C#
I have a stored procedure that can return up to 7 recordsets (depending on the parameters passed in).
I need to know how I can simply return all the recordsets as individual DataTables so that I can loop through whatever is there, skipping to the next DataTable when I get to the end of it without having to run multiple SQL statements and use multiple adapter.Fill statements to add each table into a DataSet.
In classic it was a simple Do While not objRS.EOF loop with a objRS.NextRecordset() when I got to the end of the loop to move to the next statement.
Is there anything I can use that doesn't require a total rewrite of the current back end code?
Each recordset has a different number of columns and rows. They are unrelated to each other. We return multiple recordsets from Stored Proc's to reduce traffic.
Examples would be nice.
Thanks
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();
After this you can take advantage of different (7) recordsets using
ds.Tables[0]
ds.Tables[1]
ds.Tables[2]
ds.Tables[3]
ds.Tables[4]
ds.Tables[5]
ds.Tables[6]
这篇关于从存储过程在C#中返回的多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!