executetennonquery和dataadapter.fill有什么区别? [英] What is the difference between executennonquery and dataadapter.fill?

查看:67
本文介绍了executetennonquery和dataadapter.fill有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到exceutenonquery和dataadatper.fill在操作数据表的数据方面都做了同样的事情。但是,我不明白有什么不同,为什么一个应该用于另一个?有人可以解释一下这个吗?



我尝试了什么:



一般关于如何使用事物以及原因的问题。

I noticed that both exceutenonquery and dataadatper.fill both do the same thing in terms of manipulating the data of a datatable. However, I do not understand what the difference is and why one should be used over the other? can someone explain this?

What I have tried:

General question on how things should be used and why.

推荐答案

Dataadapter.Fill用于将数据填充到数据集或数据表中,而Command.ExecuteNonQuery可用于UPDATE ,DELETE,INSERT操作,执行存储过程等。



看看

- 从DataAdapter填充数据集Microsoft Docs [ ^ ]

- SqlCommand.ExecuteNonQuery Method(System.Data.SqlClient)| Microsoft Docs [ ^ ]
Dataadapter.Fill is used for populating data into a dataset or a datatable while Command.ExecuteNonQuery can be used for UPDATE, DELETE, INSERT operations, executing stored procedures etc.

Have a look at
- Populating a DataSet from a DataAdapter | Microsoft Docs[^]
- SqlCommand.ExecuteNonQuery Method (System.Data.SqlClient) | Microsoft Docs[^]


引用:

I注意到exceutenonquery和dataadatper.fill在操作数据表的数据方面都做了同样的事情。

I noticed that both exceutenonquery and dataadatper.fill both do the same thing in terms of manipulating the data of a datatable.





你在这里混淆了一些东西。 SqlCommand ExecuteNonQuery 不会操纵 DataTable中的数据。它的目的是执行 INSERT UPDATE DELETE 和无论您是在执行原始SQL字符串还是StoredProcedure,都会返回受影响的行。 SqlDataAdapter.Fill()方法从数据库中检索(选择或获取)数据到指定的 DataSet DataTable 。如果您正在处理来自SQL查询/ SP的多个表结果,通常会使用 DataSet ,否则,您将只使用 DataTable 处理单个结果集。



You are confusing things here. The SqlCommand ExecuteNonQuery will not manipulate the data in the DataTable. It's purpose is to execute INSERT, UPDATE or DELETE and returns the affected rows regardless if you are executing a raw SQL string or StoredProcedure. The SqlDataAdapter.Fill() method retrieves (selects or fetches) your data from your database to a specified DataSet or a DataTable. You would normally use DataSet if you are dealing with multiple table results from your SQL query /SP, otherwise, you will only use DataTable to deal to single result set.


这篇关于executetennonquery和dataadapter.fill有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆