下面代码为何运行不出来?哪里写错了,我想把数据库的数据写到新生成的dc.txt文件中
Dim objConnection 'CONNECTION对象实例
Dim objRecordSet 'RECORDSET对象实例
Dim objCommand '命令对象实例
Dim strConnectionString '连接字符串
Dim objField
Dim intArrayLength '数组长度
Dim i
Set objConnection = CreateObject("ADODB.CONNECTION")
strConnectionString = "DSN=AR System ODBC Data Source;ARServer=globalar.jci.com;UID=ayuang;PWD=Jame12
$;ARAuthentication=;ARUseUnderscores=1;SERVER=NotTheServer"
objConnection.Open strConnectionString
If (objConnection.State = 1) Then
MsgBox "数据库连接成功!"
End If
If (objConnection.State = 0) Then
MsgBox "连接数据库失败!"
End If
i = 0
str_Array_QueryResult = Array() '重新初始化数组为一个空数组
Set rs = CreateObject("ADODB.RECORDSET") '4 - 建立RECORDSET对象实例
Set objCommand = CreateObject("ADODB.COMMAND") '5 - 建立COMMAND对象实例
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT "&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Case ID+"&chr(34)&" from "&chr(34)
&"HPD:HelpDesk"&chr(34)&" "&chr(34)&"HPD:HelpDesk"&chr(34)&" WHERE ("&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Assigned To
Group+"&chr(34)&" Like "&chr(39)&"%apac.gen.as%"&chr(39)&") OR ("&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Entry
Group"&chr(34)&" Like "&chr(39)&"%apac.gen.as%"&chr(39)&") ORDER BY "&chr(34)&"HPD:HelpDesk"&chr(34)&"."&chr(34)&"Case
ID+"&chr(34)&""
rs.CursorLocation = 3
rs.Open objCommand '6 - 执行SQL语句,将结果保存在RECORDSET对象实例中
MsgBox "数据查询完成!" 'intArrayLength = objRecordSet.RecordCount 将查询结果的行数作为数组的长度
Open "C:\Documents and Settings\Administrator\dc.txt" For Output As #1
For j = 0 To rs.Fields.Count - 1
Print #1, rs.Fields(j).Name; Space(16);
Next j
Print #1,
For i = 0 To rs.RecordCount - 1
For j = 0 To rs.Fields.Count - 1
s = Trim(rs.Fields(j) & "")
If s = "" Then
Print #1, s; Space(20);
Else
Print #1, s; Space(20 - LenB(StrConv(s, vbFromUnicode)));
End If
Next j
Print #1,
rs.MoveNext
Next i
Close #1
MsgBox "导出完成"
rs.MoveFirst
Shell "C:\Documents and Settings\Administrator\dc.txt", vbNormalFocus
[解决办法]