在excel vba中利用ado调用ms sql server中的存储过程(例如sp_helpdb pubs),该存储过程返回多个结果集(结果集的结构并不相同),想把这多个结果集都在excel中显示出来,可是只会显示第1个结果集,不知道如何才能显示出所有结果集,请问该如何修改代码才行? Sub COPYRESULT() Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim SQL As String, mydata As String Dim i As Integer mydata = "excelsql" cnn.ConnectionString = "provider=sqloledb;user id=sa;password=excel;data source=worker;initial catalog=" & mydata cnn.Open SQL = "UP_JZYYL" Set rs = cnn.Execute(SQL) Cells.Clear For i = 0 To rs.Fields.Count - 1 Cells(1, i + 1) = rs.Fields(i).Name Next i Range("a2").CopyFromRecordset rs Cells.Columns.AutoFit rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing End Sub |