VBS连接数据库,参考了点资料
‘建立连接
Dim Cnn ‘定义数据库连接串
Set Cnn = CreateObject("ADODB.Connection")
sql="DSN=*;DATABASE=*;PWD=*;SERVER=*;UID=*"
Cnn.ConnectionString = sql
Cnn.Open ‘打开数据库连接
If Cnn.State <> 0 Then ‘判断数据库连接是否成功
WScript.echo "数据库连接成功"
else
WScript.echo "数据库连接失败"
Wscript.quit
End If
‘打开记录
dim rs,ssql
Set rs = CreateObject("adodb.recordset")
ssql="select columnname from tablename"
rs.Open ssql, Cnn, 1, 3
rs.MoveFirst
‘读取记录
Do Until rs.EOF
WScript.Echo rs.Fields("columnname")
rs.MoveNext
Loop
‘释放资源
rs.Close
Cnn.Close
Set rs = Nothing
Set Cnn = Nothing
注:在ODBC里面设置数据源后,填写*字符串
最后成功查出:附图
原文地址:http://www.cnblogs.com/presists/p/3848744.html