我在我的项目中使用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?)
答案 0 :(得分:0)
更改GetCompanies()方法(首选)或DAL ExecuteReader()方法的返回类型。