SqlCommand 还是 SqlDataAdapter? [英] SqlCommand or SqlDataAdapter?

查看:15
本文介绍了SqlCommand 还是 SqlDataAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个类似于小型收银员应用程序的东西,用于记录客户、员工、服务、销售和约会.我正在使用 Windows 窗体,并在该 DataGrids 中.我已经创建了要用于应用程序的数据库.我想知道是否应该改用 SqlCommand-SqlDataReader 或 SqlDataAdapter-DataSet.哪种方法更好?

I'm creating something like a small cashier application that keeps record for the clients, employees, services, sales, and appointments. I'm using windows forms, and within that DataGrids. I've created the database that I'm going to be using for the application. I want to know if I should use SqlCommand-SqlDataReader or SqlDataAdapter-DataSet instead. Which approach is better?

推荐答案

这在很大程度上取决于您想要的操作类型.

This is highly depend upon type of operation you want.

以下是我的建议.

  1. 如果您想更快地读取数据,请使用 SQLDataReader,但这是您需要采取的操作成本在那之后的阅读过程中.打开连接读取数据关闭连接.如果您忘记关闭,则会影响性能.

  1. If you want to read data faster go for SQLDataReader but that comes as cost of operation you need to take during read after that also. Open Connection Read Data Close Connection. If you forgot to close than it will hit performance.

使用 SQLDataAdapter

Go for SQLDataAdapter

  • 如果您想更快地阅读并使用 Disconnected Arch 的好处.ADO.net 的
  • 这将自动关闭/打开连接.
  • 此外,它还允许您自动将 DataSet 中的更新处理回 DataBase.(SqlCommandBuilder)

使用 SQLCommand(当您读取 SQLDataReader 以读取数据时也会用到)以及用于插入和更新.

Use SQLCommand ( This will also comes when you read SQLDataReader for read data) and for insert and update.

  • 这将为您提供更好的插入和更新性能.

如果您使用的是 .NET Frame 3.5 sp1 或更高版本,我建议 Linq to SQL 或实体框架也可以解决你的目的.

If you are using .NET Frame 3.5 sp1 or later i would suggest Linq to SQL or Entity Framework would also solve your purpose.

谢谢.

这篇关于SqlCommand 还是 SqlDataAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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