我通过ADO对象,调用recordset对象的open方法,执行一条对数据库进行更新的SQL语句,然后,需要通过datagrid控件,将改变后的数据库,显示出来,那么,我的datasource属性应该如何设置?我怎么看到很多书都在回避这一点?是不是不能连接?请教各位.

解决方案 »

  1.   


        Dim CN   As New ADODB.Connection                '定义数据库的连接
        Dim Rs   As New ADODB.Recordset
        CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=northwind;User Id=sa;Password=sa;"    CN.Open
        
        Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adLockOptimistic    Set DataGrid1.DataSource = Rs
      

  2.   

    Dim CN   As New ADODB.Connection                '定义数据库的连接
        Dim Rs   As New ADODB.Recordset
        CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=northwind;User Id=sa;Password=sa;"    CN.Open    cn.execute "update emploees set name='sdfd' where id=3"    Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adLockOptimistic    Set DataGrid1.DataSource = Rs
      

  3.   

    好象会报错的。数据类型不符,我前几天也遇到这个问题了。
    是不是要datagride1.datasource=rs.source?