我以前用DATAENVIRONMENT
现在想学一下用ADO代码通过ODBC连接SQL 7.0 数据库
或直接用ADO代码连接到SQL 7.0数据库
连接时后请对数据库操作一下比如SELECT 等
连接结束后请断开与数据库的连接.
请写出详细代码和说明.
谢谢!

解决方案 »

  1.   

    Dim CN   As New ADODB.Connection                '定义数据库的连接存放数据和代码
        Dim Rs   As New ADODB.Recordset
        CN.ConnectionString = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=wktrade;Data Source=net5"
        CN.Open
        Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adLockBatchOptimistic
       Set DataGrid1.DataSource = Rs
    CN.CLOSE
    RS.CLOSE
    SET CN=Nothing
    set Rs=nothing
      

  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
        Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adLockBatchOptimistic
       Set DataGrid1.DataSource = Rs
      

  3.   

    Dim oConnect As New ADODB.Connection
    Dim strConnection as String
    Dim strSQL as StringstrConnection ="Provider=sqloledb.1;Persist Security Info=False;User ID=sa;Initial Catalog=nbkyz;Data Source=192.168.0.1;Password=123"
    oConnect.Open strConnection strSQL="SELECT function_id FROM user_function_aid WHERE  user_id='centertest' AND  function_id='QueryBusInfo'"oConnect.Execute strSQLoConnect.Close
      

  4.   

    这句能详细解释一下吗?以后便灵活运用!    CN.ConnectionString = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=wktrade;Data Source=net5"里的Provider=SqlOleDb.1 这是什么意思?还有别的参数吗?
    Persist Security Info=true这是什么意思?还有别的参数吗?
    Rs.CursorLocation = adUseClient这是什么意思?还有别的参数吗?
      

  5.   

    Provider属性指定 OLE DB 提供者,比如Access可以用Microsoft.Jet.OLEDB.4.0rs.CursorLocation 表示 调用支持批更新的“客户端游标提供者”,其它可选参数还有adUseNone 和 adUseServer,具本使用方法参考MSDNPersist Security Info属性: Syntax
    object.Properties("Persist Security Info") [= value]Parts
    objectExpression that evaluates to an object in the Applies To list.valueBoolean that specifies whether the data source can persist authentication information, as specified in Settings.Settings
    Value Description 
    True The data source object can persist sensitive authentication information such as a password along with other authentication information. 
    False The data source object cannot persist sensitive authentication information.