いいえ、SqlDataReader
は転送のみです。私の知る限り、リーダーを開いてKeyInfo
、リーダーのメソッドで作成されたスキーマ データ テーブルを調べることが最善のGetSchemaTable
方法です (または、フィールドを調べるだけです。これは簡単ですが、信頼性は低くなります)。
私はこれに数日を費やしました。私は結局、物理的な秩序依存と一緒に暮らすことになりました。コード メソッドとストアド プロシージャの両方に でコメントを付け、ストアド プロシージャの出力を検証する必要がある場合に結果セットを出力する!!!IMPORTANT!!!
を含めました。#If...#End If
次のコード スニペットが役立つ場合があります。
役立つコード
Dim fContainsNextResult As Boolean
Dim oReader As DbDataReader = Nothing
oReader = Me.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.KeyInfo)
#If DEBUG_ignore Then
'load method of data table internally advances to the next result set
'therefore, must check to see if reader is closed instead of calling next result
Do
Dim oTable As New DataTable("Table")
oTable.Load(oReader)
oTable.WriteXml("C:\" + Environment.TickCount.ToString + ".xml")
oTable.Dispose()
Loop While oReader.IsClosed = False
'must re-open the connection
Me.SelectCommand.Connection.Open()
'reload data reader
oReader = Me.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.KeyInfo)
#End If
Do
Dim oSchemaTable As DataTable = oReader.GetSchemaTable
'!!!IMPORTANT!!! PopulateTable expects the result sets in a specific order
' Therefore, if you suddenly start getting exceptions that only a novice would make
' the stored procedure has been changed!
PopulateTable(oReader, oDatabaseTable, _includeHiddenFields)
fContainsNextResult = oReader.NextResult
Loop While fContainsNextResult