C# SQLCommandBuilder 帮助
我有一个项目想要使用 sqlcommandbuilder。
我唯一的问题是我找不到如何使用它的像样的例子,或者只是不明白为什么要这样使用它。
我正在基于三层架构构建我的应用程序。
比如说我想生成一个更新语句。命令构建器从哪里获取值以更新到数据库中。我目前正在使用普通的 sql 命令并手动创建每个 sql 语句。但由于多个数据库表往往会很麻烦,并且会变得混乱。
这是我的软件工程学科的期末项目。请需要帮助。
I have project where i want to use the sqlcommandbuilder.
My only problem is that i can not find a decent example of how to use it, or just simply does not understand why it is used like that.
I am building my application based on 3-tier architecture.
Lets say for instance i want to generate a update statement. where does the commandbuilder get the value from to update into the database. i am currently using the normal sqlcommand and manually creates every sql statement. but tends to be a hassle due to multiple database tables, and it gets confusing.
This is for my final project for my software engineering subject. Please need help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我赞同上面评论中的观点……一个好的 ORM 绝对值得一看。
http://msdn.microsoft.com/en-us /library/system.data.sqlclient.sqlcommandbuilder.aspx
注意:MS 提供的示例实际上相当不错。
他们几乎说了我想说的一切。
如果您需要更多内容,则需要手动生成 SQL 语句,然后将它们加载到 CommandBuilder 中。
命令生成器与 DataTable 配合得相当好,而 DataTable 又可以绑定到 ASP.Net 中的 DataView。
相比之下,一个好的 ORM(前提是您的数据库受支持),例如 nhibernate,可以生成多表更新 + 为您提供一定程度的数据库供应商独立性。
学习它的一个很好的理由是,您可以回答 MS 认证考试中出现的任何问题,或者也许在使用您选择的 ORM 不支持的数据库时......或者也许您只是想得到快速启动并运行的东西。
I second the remarks in the comments above... a good ORM is definitely worth looking at.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx
Note: the example that MS have there is fairly good actually.
They pretty much say everything I'd have said.
if you need anything more than that, you'll need to generate the SQL statements by hand, and then load them into the CommandBuilder.
the command builder works reasonably well with a DataTable, which in turn can be bound to a DataView in ASP.Net.
By contrast, a good ORM (provided your database is supported) such as nhibernate, can generate multi-table updates + give you a degree of database vendor independence.
A good reason to learn it is so that you can answer any questions that come up in MS certification exams, or perhaps when using databases unsupported by your ORM of choice... or maybe your just want to get something up and running quickly.