VB 6 不用很久了,Connection / ConnectionString 这个却是很少用到的,有时还真没记下它,现记于此。
Dim Cn As New ADODB.Connection Dim rst As New ADODB.Recordset ' 第一种方法 Cn.ConnectionString = "Provider=sqloledb;Data Source=192.168.1.10;Initial Catalog=DBName;User ID=MyID;Password=MyPass" Cn.Open ' 第二种方法' Set Cn = New ADODB.Connection' Cn.CursorLocation = adUseClient' Cn.Provider = "sqloledb.1"' Cn.ConnectionString = "192.168.1.10"' Cn.ConnectionTimeout = 3600' Cn.Open,"MyID","MyPass"' Cn.DefaultDatabase = "DBName" rst.Open "select * from TableName",Cn,adOpenKeyset,adLockPessimistic