Questions tagged [sqldatareader]

Provides a way of reading a forward-only stream of rows from a SQL Server database.

The SqlDataReader is a member of the .NET framework's System.Data.SqlClient family responsible for reading data from a SQL database. The SqlDataReader is created by calling the ExecuteReader() method of the SqlCommand object, instead of directly using a constructor.

While the SqlDataReader is being used, the associated SqlConnection is busy serving the SqlDataReader, and no other operations can be performed on the SqlConnection other than closing it. This is the case until the Close method of the SqlDataReader is called. For example, you cannot retrieve output parameters until after you call Close.

Changes made to a result set by another process or thread while data is being read may be visible to the user of the SqlDataReader. However, the precise behavior is timing dependent.

For optimal performance, SqlDataReader avoids creating unnecessary objects or making unnecessary copies of data. Therefore, multiple calls to methods such as GetValue return a reference to the same object. Use caution if you are modifying the underlying value of the objects returned by methods such as GetValue.

References

MSDN Article

1132 questions
0
votes
1 answer

DataSet OR DataReader for this case

I have a need to iterating through 2 tables, first iterate 1 tables and based on its value fetch and iterate the other table. It likes GetAllEmployeeName For each employee get and iterate All Sub Employees and do some OPERATION. Now I am using…
Akon
  • 272
  • 1
  • 6
  • 20
0
votes
2 answers

Memory problems while selecting many rows

I am retrieving rows from large table (1.8 GB, 20 milions of records) with DataReader. The SQL Server (2008 R2) consumes a lot of memory and (sometimes) doesn't survive this query. It is probably holding the whole result in memory and returning the…
0
votes
1 answer

C# SQL ReaderData and command together

Please can you help me? I have problem that i want use data from SQL reader to command for update but it still say me that i must first close reader before update, but if i will close my reader so that my next data will be not updated. Please have…
Radek Tarant
  • 227
  • 1
  • 5
  • 14
0
votes
2 answers

Asyncronous While Loop?

I have a pretty great SqlDataReader wrapper in which I can map the output into a strongly typed list. What I am finding now is that on larger datasets with larger numbers of columns, performance could probably be a bit better if I can optimize my…
Kevin
  • 2,684
  • 6
  • 35
  • 64
0
votes
1 answer

What to do from preventing SQLdatareader to return NULL?

I have a problem with a method that looks like the following: public SqlDataReader statistiekenDocentBekijken(int docentid) { //Conectie met de database SqlConnection connectie = new SqlConnection("user id=bbbbb;" + …
Niek Jonkman
  • 1,014
  • 2
  • 13
  • 31
0
votes
2 answers

XLinq vs. SqlDataReader performance

As a part of trying to repair stuff in a fairly messed up legacy system I have a method making a call to a stored procedure in our SQLServer database. Nothing in this set up is ideal, but it is what I have got to work with. The two options I have is…
Mia Clarke
  • 8,134
  • 3
  • 49
  • 62
0
votes
1 answer

SqlDataReader: Combine Records in One String with Delimeters

I would like to combine 2 or more records in a single string based from SqlDataReader data. SqlDataReader data = cmd.ExecuteReader(); string category = ""; while (data.Read()) { category = data["Column1"].ToString() + ", " +…
abramlimpin
  • 5,027
  • 11
  • 58
  • 97
0
votes
1 answer

Invalid character for ; using reader.NextResult

string sql = @"SELECT sum(subtotal) FROM table1 WHERE clientid=:v1;" + "SELECT * FROM table2 WHERE clientid = :v2 " cmd = DBConnection.GetCommand(); cmd.CommandText = sql; cmd.Parameters.Clear(); cmd.Parameters.Add(":v1",…
user2369009
  • 555
  • 2
  • 5
  • 11
0
votes
3 answers

Concept of handling SqlCommand in C#

I'm trying to select a list of users from the database and send email to each of every users based on a condition isSent == false. After send email to them, the value of this false should be update to true. Below code is the way i retrieve list of…
SuicideSheep
  • 5,260
  • 19
  • 64
  • 117
0
votes
1 answer

I get only column headers using sqldatareader and datagridview

I have a SQL Server 2008 express with a database and a table and using VB 2010 express. I am trying to read from that table with sqldatareader, but I only one row in the datagridview with the column headers, no row with data. What am I doing wrong?…
0
votes
1 answer

Asp.net SQLdatareader while loop keeps getting passed over

For some odd reason, my while loop is being completely ignored. The breaking point shows that it at least is getting to it, but not even attempting to go within. It's probably something simplistic that I'm missing. namespace website { public…
Vash
  • 332
  • 3
  • 14
0
votes
1 answer

Insert-Update Error from SQLDataReader in Webservice

I have a webservice that either adds or updates room inventory based on whether it is available or not. (Code below). The problem I am having with this code is that it will either do a add or an update for the entire range or throw an error like for…
user1270384
  • 711
  • 7
  • 24
  • 53
0
votes
4 answers

Add record to SqlDataReader

Is there any way I can push a new record to SqlDataReader after i pull a table down? I have this piece of trash code that I need to modify, and this seems like the easiest way to do what I need. I understand that this should not be done, and if you…
Dested
  • 6,294
  • 12
  • 51
  • 73
0
votes
2 answers

How can I populate two DataTables from one SqlDataReader

I have two DataTables, and I need to populate them from one SqlDataReader. Reason for this is that I created join in my sql query and I want to populate two tables from reader that contains them. I used Load method from DataTable but that only works…
stanke
  • 276
  • 2
  • 13
0
votes
0 answers

Argument of Out Range Exception while trying to read data from a List

I have a method that reads data from a database table using SqlDataReader. i assign data retrieved by SqlDataReader into a List and return it. when i want to assign the List data from method into the List on Code behind file, i encounter the…
Iatrochemist
  • 256
  • 7
  • 19