[英]Difference between using the Load method of the Dataset or the Fill method of the DataAdapter
Can anyone tell me difference in two below methods of geting records from SQL DB ? 谁能告诉我以下两种从SQL DB获取记录的方法的区别?
Declarations 声明书
Dim Cmd As New OdbcCommand
Dim OdbcDr As OdbcDataReader
Dim OdbcAd As OdbcDataAdapter
Method one : Using OdbcDataReader and Loading data in Data Table 方法一:使用OdbcDataReader并在数据表中加载数据
OdbcDr = Cmd.ExecuteReader()
dt.Load(OdbcDr)
Return dt
Method two: Using OdbcDataAdapter and filling data in Data Table 方法二:使用OdbcDataAdapter并将数据填充到数据表中
OdbcAd = New OdbcDataAdapter(Cmd)
OdbcAd.Fill(dt)
Return dt
Which method I should use ? 我应该使用哪种方法?
A DataReader is exactly what it sounds like, all it does is read from the source and allows you to do whatever with the results. DataReader确实是听起来很像的东西,它所做的一切都是从源中读取的,并允许您对结果进行任何处理。 In contrast, a DataAdapter is a two-way bridge between you and the data.
相反,DataAdapter是您与数据之间的双向桥梁。 You can use the Fill() method to retrieve data from your connection but it also works the other way around, where you can use the Update() method to pass changes from your DataSet/DataTable into your database.
您可以使用Fill()方法从连接中检索数据,但是它也可以以其他方式起作用,您可以使用Update()方法将更改从DataSet / DataTable传递到数据库中。
AFAIK there's no real reason to use a DataAdapter where a DataReader will do, it should be faster. AFAIK没有真正的理由在DataReader可以使用的地方使用DataAdapter,它应该更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.