MSSQL:ADO连接数据库

来源:互联网 发布:北京游戏编程培训 编辑:程序博客网 时间:2024/05/18 21:44


1、VB6连接SQLSERVER2014:


Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset

Private Sub Form_Load()
    Con.ConnectionString = "Driver={sql server};server=192.168.1.104;uid=sa;pwd=;database=db_2008"
    Con.Open
    Rs.Open "select * from test", Con, adOpenKeyset, adLockOptimistic
    Set ms1.DataSource = Rs
    Con.Close
End Sub


2、excel2013连接SQLSERVER2014:

Private Sub CommandButton1_Click()

Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset

    Con.ConnectionString = "Driver={sql server};server=wjpc;uid=sa;pwd=;database=db_2008"
    Con.Open
    Cells(1, 1).CopyFromRecordset Con.Execute("select * from aa")

    Con.Close

End Sub


3、总结:"server="用来控制服务器

原创粉丝点击