1

以下のクエリの結果を取得しようとしていますが、XML 文字列 [処理済みデータ] に到達すると、結果を Excel に表示できません。誰か助けてください。ありがとう

Public Sub Load_Error()
Dim ADOC As New ADODB.Connection
Dim SQL1 As String
Dim rst1 As New ADODB.Recordset
Dim i As Integer
Dim r As Integer

'#### Server Information
Server_Name = "A"
Database_Name = "B"

'#### Server Connection is opened

Worksheets("Load Errors").Activate

r = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Range(Cells(1, 1), Cells(r, 6)).ClearContents

ADOC.Open "Provider=MSDASQL.1;DRIVER=SQL Server;SERVER=" & Server_Name & ";DATABASE=" & Database_Name & ";Trusted_Connection=Yes"

SQL1 = "SELECT [CreatedDate],[RecordStatus],[Comment], CONVERT(varchar(max),[ProcessedData]) as [Error Message], [DataExceptionID], [SessionID] " & _
" FROM [C].[dbo].[D](nolock) " & _
" where CreatedDate >= DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) and comment not in  ('FrontierPositionRecon Load Errors','Errors', 'MCAP load errors') " & _
" order by createddate asc "

ADOC.CommandTimeout = 600
Set rst1 = ADOC.Execute(SQL1)

ActiveSheet.Cells(2, 1).CopyFromRecordset rst1
For i = 0 To rst1.Fields.Count - 1
    ActiveSheet.Cells(1, i + 1).Value = rst1.Fields(i).Name
Next

Set rst1 = Nothing
Set ADOC = Nothing


End Sub
4

1 に答える 1

1

理由はわかりませんが、交換すると

rst1 = ADOC.Execute(SQL1) を設定します。

rst1.Open SQL1、ADOC、adOpenStatic

できます。

于 2013-09-23T15:25:40.983 に答える