ADO使用技巧

来源:互联网 发布:淘宝刻假公章退货了 编辑:程序博客网 时间:2024/05/06 09:03

1.可以在一个线程中多打开几个 sqlconnection ,一个操作就打开一个,然后close,dispose,因为

同一个sqlconnection,只能支持一个事务。。

2.

a.  Adapter.selectommand 与da.fill是配对使用的(用与查询后填充table)

SqlCommand cmd = new SqlCommand("select * from sysDatabases", this.masterCon);
da.SelectCommand = cmd;
DataSet dsOfDb = new DataSet();
da.Fill(dsOfDb,"databases");

b. DataGridView是与dataSet绑定的,对datagridview 的修改都会与dataset同步更新

一般对datagridview的修改都需要如下方法对数据库进行更新:

SqlCommandBuilder scb = new SqlCommandBuilder(this.da);
 this.da.Update(this.ds.Tables["FirstCusts"]);  //用于除了查询以外的其他操作,sql会动态生成增删改的动态命令对数据库进行相应的修改

3. 

SqlDataAdapter,sqlcommand都可以临时构造,然后再和sqlConnection进行连接即可

4.

Adapter.Update(dataSet) // 此种方法只更新本地中的dataset,不同步更新数据库中的table

原创粉丝点击