使用DataTables代替DataReaders

使用DataTables代替DataReaders

本文介绍了使用DataTables代替DataReaders:一个好习惯吗? (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,全部!
您如何在我的DAO类上只使用DataTables而不是DataReader呢?

我想改变经典:

Hey, all!
What do you think about working only with DataTables instead DataReaders on my DAO classes?

I thought to change the classic:

public IList<client> ReadAll()
{
    String selectString = "SELECT * FROM CLIENTS";
    IList<client> clients = new List<client>();
    using (var selectCommand = new OracleCommand(connection, selectString))
    {
        using (OracleDataReader selectReader = selectCommand.ExecuteReader())
        {
           if (selectReader.HasRows)
           {
               while (selectReader.Read())
               {
                   clientes.add( GetDomainObject(selectReader) );
               }
               selectReader.close();
           }
        }
    }
    return clients;
}
</client></client></client>



通过这种方式将数据从数据库获取到我的集合:



for this way to get data from database to my collection:

public IList<client> ReadAll()
{
    String selectString = "SELECT * FROM CLIENTS";
    IList<client> clients = new List<client>();
    using (var adapter = new OracleDataApdater(connection, selectString))
    {
        DataTable datatableClients = new DataTable("CLIENTS");
        adapter.Fill(datatableClients);
        foreach (DataRow datarowClient in datatableClients.Rows)
        {
            clients.add( GetDomainObject(datarowClient) );
        }
    }
    return clients;
}
</client></client></client>



在我的DAO类上进行此更改时,您看到任何好处吗?
谢谢大家!



Do you see any advantage in do this change on my DAO classes?
Thanks all!

推荐答案




这篇关于使用DataTables代替DataReaders:一个好习惯吗? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:24