Dim StrCon As String StrCon = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;" _ & "Initial Catalog=你的数据库名称;Data Source=" & 你的IP地址 & ";" _ & "Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;" _ & "Use Encryption for Data=False;Tag with column collation when possible=False"
dim AcSys as new adodb.connection With AcSys If .State = adStateOpen Then .Close .ConnectionString = StrCon .ConnectionTimeout = 30 .Open End With
Sub sql() Dim iRe As ADODB.Recordset Dim iConc As String
iConc = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _ "User ID=用户名;Password=密码;Initial Catalog=DATABASE1;Data Source=远程SQL服务器名" Set iRe = New ADODB.Recordset iRe.Open "TABLE1", iConc, adOpenKeyset, adLockOptimistic Debug.Print iRe.Fields("字段名") iRe.Close End Sub
public function ececute(byval sql as string)as adodb.recordset... conn="provider=sqloledb;data source=127.0.0.1;use id=sa;password=; initial catalog=库名;" ... txtsql="select * from table" set mrc=execute(txtsql)
dim ac_tmp as new adodb.connection dim ar_tmp as new adodb.recordset with ac_tmp ... ... end withtxtSQL = "select 名称 from 学生表 where 号码='"& combobox.text &"'" with ar_tmp if .state=adstateopen then .close .open txtSQL,ac_tmp,adopenkeyset,adlockreadonly end withif ar_tmp.recordcount>0 then text.text=ar_tmp!名称 else text.text="" endif ar_tmp.close
StrCon = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;" _
& "Initial Catalog=你的数据库名称;Data Source=" & 你的IP地址 & ";" _
& "Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;" _
& "Use Encryption for Data=False;Tag with column collation when possible=False"
dim AcSys as new adodb.connection
With AcSys
If .State = adStateOpen Then .Close
.ConnectionString = StrCon
.ConnectionTimeout = 30
.Open
End With
Dim iRe As ADODB.Recordset
Dim iConc As String
iConc = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
"User ID=用户名;Password=密码;Initial Catalog=DATABASE1;Data Source=远程SQL服务器名"
Set iRe = New ADODB.Recordset
iRe.Open "TABLE1", iConc, adOpenKeyset, adLockOptimistic
Debug.Print iRe.Fields("字段名")
iRe.Close
End Sub
conn="provider=sqloledb;data source=127.0.0.1;use id=sa;password=;
initial catalog=库名;"
...
txtsql="select * from table"
set mrc=execute(txtsql)
dim ar_tmp as new adodb.recordset
with ac_tmp
...
...
end withtxtSQL = "select 名称 from 学生表 where 号码='"& combobox.text &"'"
with ar_tmp
if .state=adstateopen then .close
.open txtSQL,ac_tmp,adopenkeyset,adlockreadonly
end withif ar_tmp.recordcount>0 then
text.text=ar_tmp!名称
else
text.text=""
endif
ar_tmp.close