当我需要sql命令生成器时 [英] when i need sql command builder

查看:115
本文介绍了当我需要sql命令生成器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pl解释了命令生成器的作用

pl explain the role of command builder

推荐答案

遍布
All over here

Let me know for further info. :)


SqlDataAdapter不会自动生成Transact-SQL语句,该语句需要将对DataSet所做的更改与SQL Server的关联实例进行协调.但是,如果设置了SqlDataAdapter的SelectCommand属性,则可以创建SqlCommandBuilder对象以自动为单表更新生成Transact-SQL语句.然后,SqlCommandBuilder会生成您未设置的任何其他Transact-SQL语句.

每次设置DataAdapter属性时,SqlCommandBuilder都会将自身注册为RowUpdating事件的侦听器.您一次只能将一个SqlDataAdapter或SqlCommandBuilder对象彼此关联.

为了生成INSERT,UPDATE或DELETE语句,SqlCommandBuilder使用SelectCommand属性自动检索所需的元数据集.如果在检索元数据之后(例如在第一次更新之后)更改SelectCommand,则应调用RefreshSchema方法来更新元数据.

SelectCommand还必须至少返回一个主键或唯一列.如果不存在,则会生成InvalidOperation异常,并且不会生成命令.

SqlCommandBuilder还使用SelectCommand引用的Connection,CommandTimeout和Transaction属性.如果修改了这些属性中的一个或多个,或者替换了SelectCommand本身,则用户应调用RefreshSchema.否则,InsertCommand,UpdateCommand和DeleteCommand属性将保留其先前的值.

如果调用Dispose,则SqlCommandBuilder将与SqlDataAdapter解除关联,并且不再使用生成的命令.
The SqlDataAdapter does not automatically generate the Transact-SQL statements required to reconcile changes made to a DataSet with the associated instance of SQL Server. However, you can create a SqlCommandBuilder object to automatically generate Transact-SQL statements for single-table updates if you set the SelectCommand property of the SqlDataAdapter. Then, any additional Transact-SQL statements that you do not set are generated by the SqlCommandBuilder.

The SqlCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one SqlDataAdapter or SqlCommandBuilder object with each other at one time.

To generate INSERT, UPDATE, or DELETE statements, the SqlCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata has been retrieved, such as after the first update, you should call the RefreshSchema method to update the metadata.

The SelectCommand must also return at least one primary key or unique column. If none are present, an InvalidOperation exception is generated, and the commands are not generated.

The SqlCommandBuilder also uses the Connection, CommandTimeout, and Transaction properties referenced by the SelectCommand. The user should call RefreshSchema if one or more of these properties are modified, or if the SelectCommand itself is replaced. Otherwise the InsertCommand, UpdateCommand, and DeleteCommand properties retain their previous values.

If you call Dispose, the SqlCommandBuilder is disassociated from the SqlDataAdapter, and the generated commands are no longer used.


在需要时.如果您想获得更好的答案,则必须在问题上做得更好.
When you need it. If you want a better answer you''ll have to do a little better with the question.


这篇关于当我需要sql命令生成器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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