存储过程执行返回的类型
我有一个 SP,我想执行并将 groos 结果保存在一边(在类字段中)。
后来我想从这个结果中获取某些行的某些列的值。
可能返回哪些类型?哪一个最适合我的目标?
我知道有DataSet、DataReader、resultSet。还有什么?
它们之间的主要区别是什么?
I have a SP I want to execute and save the groos result aside (in a class field).
Later on I want to acquire the values of some columns for some rows from this result.
What returned types are possible? Which one is the most sutiable for my goal?
I know there are DataSet, DataReader, resultSet. what else?
What is the main difference between them ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想存储结果并稍后使用它们(如您所写),您可以使用重型数据集或通过数据读取器使用自定义容器类型填充轻量级列表。
或者,如果您想立即使用结果,请继续使用数据读取器。
结果集是旧的 VB6 类 AFAIK 或当前的 Java 接口。
If you want to store the results and use them later (as you have written), you may use the heavy data sets or fill the lightweight lists with custom container types via the data reader.
Or in case you want to consume the results immediately, go on with the data reader.
Result set is the old VB6 class AFAIK or the current Java interface.
获取数据的传统方法是使用 System.Data.SqlClient 命名空间中的类。当您只想读取记录集时,可以使用 DataReader,它是一种只读向前类型的游标,快速高效。 DataReader 是可绑定的,但您一次读取一条记录,因此无法返回,例如。如果记录集非常大,那么读取器也很好,因为它一次在内存中只存储一条记录。
您可以使用 DataAdapter 并获取 DataSet,然后您可以完全控制 DataSet 类中的所有数据。它在系统上较重,但当您需要处理应用程序中的数据时非常强大。如果查询返回多个记录集,您还可以使用 DataSet。
因此,这实际上取决于从数据库获取数据后需要对数据执行什么操作。如果您只需要将其读入其他内容,请使用 DataReader,否则使用 DataSet。
The traditional way to get data is by using the the classes in System.Data.SqlClient namespace. You can use the DataReader which is a read only forward type of cursor, fast and efficient when you just want to read a recordset. DataReader is bindable but you read it one record at the time and therefore don't have the options of going back, for instance. If the recordset is very big the reader is also good because it stores just one record at the time in memory.
You can use the DataAdapter and get a DataSet and then you have a complete control of all the data within the DataSet-class. It is heavier on the system but very powerful when you need to work with the data in you application. You can also use DataSet if the query returns more than one recordset.
So it really depends on what you need to do with the data after getting it from the database. If you just need to read it into something else, use DataReader otherwise DataSet.