datareader

Multiples Table in DataReader

*爱你&永不变心* 提交于 2019-11-26 14:40:53
问题 I normally use DataSet because It is very flexible. Recently I am assigned code optimization task , To reduce hits to the database I am changing two queries in a procedure. one Query returns the count and the other returns the actual data . That is , My stored procedure returns two tables. Now, I know how to read both tables using DataSets , But I need to read both tables using DataReader . In search of that I found This. I follow the article and wrote my code like this: dr = cmd

How to fill Dataset with multiple tables?

孤者浪人 提交于 2019-11-26 14:07:29
问题 I'm trying to fill DataSet which contains 2 tables with one to many relationship. I'm using DataReader to achieve this : public DataSet SelectOne(int id) { DataSet result = new DataSet(); using (DbCommand command = Connection.CreateCommand()) { command.CommandText = "select * from table1"; var param = ParametersBuilder.CreateByKey(command, "ID", id, null); command.Parameters.Add(param); Connection.Open(); using (DbDataReader reader = command.ExecuteReader()) { result.MainTable.Load(reader); }

Is datareader quicker than dataset when populating a datatable?

五迷三道 提交于 2019-11-26 09:56:59
问题 Which would be quicker. 1) Looping a datareader and creating a custom rows and columns based populated datatable 2) Or creating a dataAdapter object and just (.Fill)ing a datatable. Does the performance of a datareader still hold true upon dynamic creation of a datatable? 回答1: The DataAdapter uses a DataReader under the hood so your experience would likely be the same. The benefit of the DataAdapter is you cut out a lot of code that would need maintenance. This debate is a bit of a religious

Convert rows from a data reader into typed results

大憨熊 提交于 2019-11-26 09:17:10
问题 I\'m using a third party library which returns a data reader. I would like a simple way and as generic as possible to convert it into a List of objects. For example, say I have a class \'Employee\' with 2 properties EmployeeId and Name, I would like the data reader (which contains a list of employees) to be converted into List< Employee>. I guess I have no choice but to iterate though the rows of the data reader and for each of them convert them into an Employee object that I will add to the

How can I easily convert DataReader to List<T>? [duplicate]

岁酱吖の 提交于 2019-11-25 23:45:51
问题 This question already has an answer here: Improve data access layer select method Pattern 7 answers Convert rows from a data reader into typed results 8 answers I have data in a DataReader which I want to be converted to a List<T> . What is a possible simple solution for this? For e.g. in CustomerEntity class, I have CustomerId and CustomerName properties.If my DataReader returns these two columns as data, then how can I convert it into List<CustomerEntity> . 回答1: I have seen systems that use