Questions tagged [idatareader]

IDataReader is a Microsoft .NET interface which can be used to read data coming from a database. Use this tag for questions about using this interface.

Provides a means of reading one or more forward-only streams of result sets obtained by executing a command at a data source, and is implemented by .NET Framework data providers that access relational databases.

References:

Related questions/examples:

Also see .

120 questions
49
votes
7 answers

Checking to see if a column exists in a data reader

Is there a way to see if a field exists in an IDataReader-based object w/o just checking for an IndexOutOfRangeException? In essence, I have a method that takes an IDataReader-based object and creates a strongly-typed list of the records. In 1…
JamesEggers
  • 12,885
  • 14
  • 59
  • 86
17
votes
2 answers

How to mock IDataReader to test method which converts SqlDataReader to System.DataView

I'm new to Moq and I'm struggling to write Unit Test to test a method which converts SqlDataAdapter to System.DataView. This is my method: private DataView ResolveDataReader(IDataReader dataReader) { DataTable table = new DataTable(); for…
Hristo
  • 859
  • 1
  • 8
  • 14
13
votes
4 answers

How do I convert a DataTable to an IDatareader?

We all know that DataReaders are quicker than DataTables since the a DataReader is used in the construction of a DataTable. Therefore given that I already have a DataTable.... Why would I want to convert it to a DataReader? Well I am creating an…
Rory Becker
  • 15,551
  • 16
  • 69
  • 94
12
votes
2 answers

c# IDataReader SqlDataReader difference

Can someone tell me the difference between these two pieces of code? Why use IDataReader? using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { // get data from the reader } } using (SqlDataReader reader =…
Nice
  • 121
  • 1
  • 3
12
votes
5 answers

Null safe way to get values from an IDataReader

(LocalVariable)ABC.string(Name) = (IDataReader)dataReader.GetString(0); This name value is coming from database. What happening here is if this name is null while reading it's throwing an exception? I am manually doing some if condition here. I…
kumar
  • 2,944
  • 18
  • 60
  • 89
10
votes
1 answer

reading from IDbCommand using an inherited custom IDataReader

I have made a custom class inherits IDataReader and have successfully implemented a custom ServerWriter sqlBulkCopy with the custom class which uses a C# object instead of DataTable. That proved to be a more efficient approach as I suspected. Now I…
Jbob Johan
  • 221
  • 1
  • 7
10
votes
4 answers

using IDataReader to call store procedure with parameters

I use IDataReader to call stored procedures without parameters. I am not finding examples of how to do this when parameters are present. Does IDataReader handle parameters of stored procedure? Please provide an example.
dan_vitch
  • 4,477
  • 12
  • 46
  • 69
8
votes
2 answers

How do I use automapper to map a dataset with multiple tables

DISCLAIMER: this is a copy paste from an older stackoverflow post that isn't available anymore, but I have exaclty the same problem, so it seemed appropriate to repost it as it was never answered. I have a stored procedure that will return 4 result…
Arne Deruwe
  • 1,100
  • 2
  • 11
  • 25
6
votes
3 answers

IDataReader and "HasColumn", Best approach?

I've seen two common approaches for checking if a column exists in an IDataReader: public bool HasColumn(IDataReader reader, string columnName) { try { reader.getOrdinal(columnName) return true; } catch { return false; …
FlySwat
  • 172,459
  • 74
  • 246
  • 311
6
votes
4 answers

How to convert/cast SqlDataReader to IDatareader

What is the easiest way to cast a SqlDataReader to IDatareader. Or is it easier / possible to convert a List<> object to a IDataReader
TheAlbear
  • 5,507
  • 8
  • 51
  • 84
5
votes
4 answers

MySqlConversionException when accessing DateTime field from DataReader

I have a C# application over MySql, using MySQL Connector; I'm trying to make a DataReader request, the query executes fine, however, when trying to access a DateTime field, i'm getting MySqlConversionException {"Unable to convert MySQL date/time…
Jhonny D. Cano -Leftware-
  • 17,663
  • 14
  • 81
  • 103
5
votes
4 answers

DataReader ordinal-based lookups vs named lookups

Microsoft (and many developers) claim that the SqlDataReader.GetOrdinal method improves the performance of retrieving values from a DataReader versus using named lookups ie. reader["ColumnName"]. The question is what is the true performance…
philrabin
  • 809
  • 2
  • 11
  • 21
4
votes
1 answer

Does IDataReader.GetName(i) work with empty data readers?

I want in the case of an empty data reader to output the field names with empty values.. ie Product: - Price: - So, are IDataReader.GetName(i) and IDataReader.FieldCount safe to use when they have no results?
Kostas Konstantinidis
  • 13,347
  • 10
  • 48
  • 61
4
votes
2 answers

Streaming compressed IDataReader using protobuf

We have a need to greatly reduce the bandwidth our back-end services use when pulling and pushing data to sql. The TDS Stream used by SqlClient is fairly bloated. For years, people have requested a compression option when pulling from sql, but…
David Thompson
  • 301
  • 1
  • 3
  • 8
4
votes
2 answers

How to implement the interface IDataReader in order to process the data before being insert?

I have a stored procedure which gives me a result set consisting of a single column which contains millions of unprocessed rows. I need to transfer these data to another server using SqlBulkCopy, but the problem is that I can't simply do the…
J. Doe
  • 63
  • 1
  • 5
1
2 3 4 5 6 7 8