可以确定、控制多个 RecordSet ADO.Net 结果集中的 RecordSet 序列吗?
我使用类似于此支持/知识库文章的代码将多个记录集返回到我的 C# 程序。
但我不希望 C# 代码依赖于返回的记录集的物理顺序来完成它的工作。
所以我的问题是,“有没有办法确定我当前正在处理多记录集结果集中的哪一组记录?”
我知道我可能可以通过查找每个结果集的唯一列名称或某些内容来间接破译这一点,但我认为/希望有更好的方法。
PS 我正在使用 Visual Studio 2008 Pro 和 Visual Studio 2008 Pro。 SQL Server 2008 Express 版。
I am using code similar to this Support / KB article to return multiple recordsets to my C# program.
But I don't want C# code to be dependant on the physical sequence of the recordsets returned, in order to do it's job.
So my question is, "Is there a way to determine which set of records from a multiplerecordset resultset am I currently processing?"
I know I could probably decipher this indirectly by looking for a unique column name or something per resultset, but I think/hope there is a better way.
P.S. I am using Visual Studio 2008 Pro & SQL Server 2008 Express Edition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,因为
SqlDataReader
只能转发。据我所知,您能做的最好的事情就是使用 KeyInfo 打开阅读器并检查使用阅读器的 GetSchemaTable 方法创建的架构数据表(或者只检查字段,这更容易,但不太可靠)。我花了几天时间在这上面。我最终只能忍受物理顺序的依赖。我用
!!!IMPORTANT!!!
对代码方法和存储过程进行了大量注释,并包含一个#If...#End If
来输出结果集当需要验证存储过程输出时。以下代码片段可能会对您有所帮助。
有用的代码
No, because the
SqlDataReader
is forward only. As far as I know, the best you can do is open the reader withKeyInfo
and inspect the schema data table created with the reader'sGetSchemaTable
method (or just inspect the fields, which is easier, but less reliable).I spent a couple of days on this. I ended up just living with the physical order dependency. I heavily commented both the code method and the stored procedure with
!!!IMPORTANT!!!
, and included an#If...#End If
to output the result sets when needed to validate the stored procedure output.The following code snippet may help you.
Helpful Code
因为您明确指定了 SQL 语句的执行顺序,所以结果将以相同的顺序出现。无论如何,如果您想以编程方式确定正在处理哪个记录集,您仍然必须识别结果中的某些列。
Because you're explicitly stating in which order to execute the SQL statements the results will appear in that same order. In any case if you want to programmatically determine which recordset you're processing you still have to identify some columns in the result.