我正在尝试根据异步函数中的数据库版本(Oracle或SQL)动态设置我的DbDataReader。 GetReaderAsync函数应该返回DataReader的类型,这样我就可以使用通用阅读器来完成其余的操作。这是我的目的,所以不要觉得有必要修复可能基于错误想法的代码,但确实提供了示例代码来完成需求。
目前我收到编译错误ReadAsync is not a member of System.Threading.Tasks.Task(Of System.Data.Common.DbDataReader)
我相信我做错了,可能在GetReaderAsync函数中。
Using reader As Task(Of Common.DbDataReader) = ConnectionController.GetReaderAsync(command) ' CType(Await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess), Oracle.DataAccess.Client.OracleDataReader)
While Await reader.ReadAsync() '<-- Compilation Error
If reader.HasRows Then
End If
End While
End Using
Public Shared Async Function GetReaderAsync(command As DbCommand) As Threading.Tasks.Task(Of DbDataReader)
'Depending on the XML value provided in the [Provider], then select the appropriate connection from
'the object oSettings of the SettingsController. The SettingsController provides a structure called Provider to choose from
If SettingsController.oSettings.Connection.provider.ToLower = SettingsController.Provider.Oracle Then
Using reader As Oracle.DataAccess.Client.OracleDataReader = CType(Await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess), Oracle.DataAccess.Client.OracleDataReader)
command.ExecuteReader()
Return reader
End Using
Else
Using reader As SqlClient.SqlDataReader = CType(Await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess), SqlClient.SqlDataReader)
command.ExecuteReader()
Return reader
End Using
End If
End Function
答案 0 :(得分:0)
的工作原理如下:
使用reader As Common.DbDataReader = Await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess)
答案 1 :(得分:0)
您可以使用Interface&#34; System.Data.IDataReader&#34;。我将它用于MySql,MSSql和Sqlite。它非常好。