我SqlDataReader
在我的项目中使用从数据库读取数据以将其发送到 Web 服务。我有这种方法来读取公司数据companyID
,companyName
但我遇到了一个铸造问题:
public static DbDataReader GetCompanies()
{
DbDataReader dr = null;
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
try
{
dr = GenericDataAccess.ExecuteReader(comm);
dr.Read();
}
catch (Exception ex)
{
throw ex;
}
return dr;
}
//ExecuteReader DAL
public static IDataReader ExecuteReader(DbCommand command)
{
try
{
command.Connection.Open();
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw;
}
finally
{
command.Connection.Close();
}
}
问题:
Error 1 Cannot implicitly convert type 'System.Data.IDataReader' to 'System.Data.Common.DbDataReader'.
An explicit conversion exists (are you missing a cast?)