0

SqlDataReader在我的项目中使用从数据库读取数据以将其发送到 Web 服务。我有这种方法来读取公司数据companyIDcompanyName但我遇到了一个铸造问题:

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?) 
4

1 回答 1

0

更改 GetCompanies() 方法(首选)或 DAL ExecuteReader() 方法的返回类型。

于 2013-02-05T19:12:19.847 回答