Questions tagged [datareader]

A DataReader reads a forward-only stream of rows from a data source.

A DataReader reads a forward-only stream of rows from a data source. This tag is for questions about creating or using a datareader in code.

782 questions
15
votes
1 answer

Handle NULL values when reading through OracleDataReader?

I'm working on my first ASP.Net application, and seem to be hitting a lot of hurdles (background primarily in WinForms with a recent MVC5 project under my belt). I am successfully making my DB connection using OracleCommand and executing my query,…
Analytic Lunatic
  • 3,853
  • 22
  • 78
  • 120
14
votes
2 answers

DataReader.GetString() via columnname

Dictionary Fields = new Dictionary(); for (int i = 0; i < reader.FieldCount; i++) { Fields.Add(reader.GetName(i), i); } this._MyField1 = reader.GetString(Fields["field1"]); this._Myfield2 = reader.GetInt16(Fields["field2"]); doing this makes…
KellCOMnet
  • 1,859
  • 3
  • 16
  • 27
13
votes
1 answer

DataReader[i] vs DataReader.GetValue(i) vs DataReader.GetString(i)

Is dataReader[i] logically equivalent to dataReader.GetValue(i) Are they the same? Are they different? Is there a situation where one would be appropriate over the other? There are documented differently: Gets the column located at the specified…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
13
votes
3 answers

WinRT No mapping for the Unicode character exists in the target multi-byte code page

I am trying to read a file in my Windows 8 Store App. Here is a fragment of code I use to achieve this: if(file != null) { var stream = await file.OpenAsync(FileAccessMode.Read); var size = stream.Size; …
Jarek Mazur
  • 2,052
  • 1
  • 25
  • 41
12
votes
2 answers

Generic Relational to Composite C# Object Mapper

I have following code that's capable of mapping Reader to simple objects. The trouble is in case the object is composite it fails to map. I am not able to perform recursion by checking the property if it is a class itself prop.PropertyType.IsClass …
Abdul Khan
  • 363
  • 3
  • 13
11
votes
4 answers

Exception of type 'System.OutOfMemoryException' was thrown. C# when using IDataReader

I have an application in which I have to get a large amount of data from DB. Since it failed to get all of those rows (it's close to 2,000,000 rows...), I cut it in breaks, and I run each time the sql query and get only 200,000 rows each time. I use…
DA_Prog
  • 263
  • 3
  • 7
  • 14
10
votes
5 answers

Using ASP.NET MVC without an ORM

In my ASP MVC application I'm using standard SQL (rather that Linq to SQL or other ORM) to query my database. I would like to pass the database results to my view and iterate over the results in my view. But I'm not sure how to do this. Every…
CoolGravatar
  • 5,408
  • 7
  • 35
  • 42
10
votes
1 answer

Dapper handling returned empty result set

We are using Dapper to map our sql data and so far it has worked very well. I have a case though where we are doing something similar to: someObject = con.Query("GetInfoSproc", p, commandType: CommandType.StoredProcedure).Single(); This works…
John Ten Cate
  • 475
  • 5
  • 16
10
votes
5 answers

IDataReader - Any way to get the total rows?

Is there any way to get the total number of rows returned from a SQL query (from the IDataReader) before iterating through the rows by using reader.Read();?
michael
  • 14,844
  • 28
  • 89
  • 177
10
votes
1 answer

Output parameters not readable when used with a DataReader

When using a DataReader object to access data from a database (such as SQL Server) through stored procedures, any output parameter added to the Command object before executing are not being filled after reading. I can read row data just fine, as…
Sean Hanley
  • 5,677
  • 7
  • 42
  • 53
9
votes
9 answers

Is datareader quicker than dataset when populating a datatable?

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…
Squiggs.
  • 4,299
  • 6
  • 49
  • 89
9
votes
2 answers

how can i loop through all of the columns of the OracleDataReader

I have the following code and i want to loop through all the fields in the result of this query and populate the dictionary called field. Given a datareader is this possible? OracleCommand command = connection.CreateCommand(); …
leora
  • 188,729
  • 360
  • 878
  • 1,366
9
votes
4 answers

Can I create an anonymous type collection from a DataReader?

I have this code: var query = "SELECT * FROM Cats"; var conn = new SqlConnection(sqlConnectionString); conn.Open(); var cmd = new SqlCommand(query); var reader = cmd.ExecuteReader(); while (reader.Read()) { var CatName =…
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
9
votes
2 answers

DataReader best-practices

Similar to this question, but the answers never really got around to what I want to know. Is there any standards around getting values from a DataReader? I.e., is this dataReader.GetString(dataReader.GetOrdinal("ColumnName")); considered…
AJ.
  • 16,368
  • 20
  • 95
  • 150
8
votes
4 answers

There is already an open DataReader associated with this Command which must be closed first

This is the code I have. /// /// Method calls stored procedure and fills DataSet of contacts associated with Lead /// /// The ID associated with a Lead /// contacts list as…
Marcus3329
  • 85
  • 1
  • 1
  • 4
1
2
3
52 53