Нет, потому что 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