MSSQL:ADO連接數據庫



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="用來控制服務器

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章