奇怪了,同一条语句在两台装一样系统的电脑里执行结果不一样
各位老师,两台电脑,都是win7(64),office2013,但是执行如下语句在把SQL表导出到excel表上显示的结果不一样Private Sub Command1_Click()
Dim conn As String
Dim rs As New ADODB.Recordset
Dim excel As Object
Dim workbook As Object
Dim sheet As Object
Dim i&, j&
conn = "Provider=SQLOLEDB;Data source=ip;initial catalog=库名;User Id=sa;Password=p"
On Error Resume Next
rs.Open "select * from 表名 where 字段='" & Text5 & "'", conn, adOpenKeyset, adLockReadOnly
Set excel = CreateObject("Excel.Application")
Set workbook = excel.Workbooks().Add()
Set sheet = workbook.Sheets(1)
excel.Visible = True
Application.WindowState = xlMaximized
ActiveWindow.WindowState = xlMaximized
For i = 0 To rs.Fields.Count - 1 '逐个字段
Cells(2, i + 1) = rs.Fields(i).Name '取字段名
Next i
[a1].CopyFromRecordset rs '数据复制到第二行
rs.Open (strSQL), cnn, adOpenKeyset, adLockReadOnly
Sheet1.Cells.ClearContents
For Each Field In rs.Fields
Sheet1.[a2].Offset(0, i) = Field.Name '字段名
i = i + 1
Next
rs.Close
Set rs = Nothing
End Sub
不同的显示结果:
A电脑能够显示SQL表的所有字段和记录,B电脑只显示所有字段名,没有记录
还请各位高人老师指导