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

SqlDataReader Force It To Read One Row At A Time

It appears that SqlDataReader reads ahead while (rdrMainLoop.Read()) { sID = rdrMainLoop.GetInt32(0); nearDupID = rdrMainLoop.IsDBNull(2) ? 0 : rdrMainLoop.GetInt32(2); sqlCmdProducer.CommandText = "update [docSVsys] set [FTSnearDupID]…
paparazzo
  • 44,497
  • 23
  • 105
  • 176
0
votes
2 answers

Datareader has rows when loading it to datatable I am getting row count = 0

try { String empid1 = Request.QueryString["MyText"]; int empid = int.Parse(empid1); string constr = System.Configuration.ConfigurationManager.ConnectionStrings["EmployeeDatabase"].ConnectionString; …
user1912987
  • 115
  • 1
  • 8
  • 19
0
votes
0 answers

Getting invalidoperationexception when using an SqlDataReader, why?

This is my code: public List fillRemarks1List(RemarksRequest oei) { List mylist = new List(); SqlConnection sqlConn = new SqlConnection(strConn); sqlConn.Open(); SqlCommand commInfo = new SqlCommand(); …
0
votes
2 answers

MVC displaying the row's data to the view

This should be a very easy question as I'm a noob and almost have it figured out myself. I'm authenticating against info in a database and I want to simply display the row's data to the view. I'm really not sure how to, I'm assuming, create a…
Batsu
  • 55
  • 1
  • 4
  • 10
0
votes
3 answers

Keeping the SqlDataReader open across an n-tiered layer

I have a Database class that abstracts the ExecuteNonQuery() and ExecuteReader() of SqlCommand. Due to wrapping the Sqlconnection and SqlCommand around using blocks, the SqlDataReader gets closed after the CustomExecuteReader() is called, therefore…
simplyme
  • 847
  • 3
  • 9
  • 20
0
votes
2 answers

How to use SqlDataReader to retrieve information from database, c#

I need to access a variable in my SQL database, along with a username which is already implemented properly. I query the database using this statement: private const string _getUserByUsernameQuery = @" SELECT [User].[username] FROM [User]…
Nibirue
  • 411
  • 1
  • 15
  • 29
0
votes
1 answer

How to add in List with sqldatareader

I am doing a program where i have used a class with 4-5 attributes public class Car { public string Make; public string Model; public int Year; public int Doors; public string Colour; public float Price; } now from sql query…
Luckyy
  • 1,021
  • 4
  • 15
  • 29
0
votes
1 answer

How do I project Datareader into a pre-defined object

I need to know how to convert the following to VB.net for an Async/Await project: public static class Extensions { public static IEnumerable Select( this SqlDataReader reader, Func projection) { while…
Bryan
  • 112
  • 1
  • 11
0
votes
1 answer

ado connection pooling connected vs disconnected

Before jumping the gun and marking duplicate, I've searched an have not had luck with a clear answer. Background: A co-worker and I had a discussion on datareader vs dataset with me on the datareader side. What it boils down to is that I like the…
ton.yeung
  • 4,793
  • 6
  • 41
  • 72
0
votes
1 answer

Using a stringbuilder as a parameter to a stored procedure and returning a dataset

I have a couple of problems relating to one of the parameters passing a number of values to a stored procedure and the result that comes back converting to dataset in order for this to be bound to an MS ReportViewer. The error I am getting says that…
Andy5
  • 2,319
  • 11
  • 45
  • 91
0
votes
0 answers

DataReader problems getting data from 2 classes

I am very inexperienced with SQL, and have only had one lesson. I am trying to figure out how to get information from 2 classes using a DataReader. My Customer class: public class Customer { private CreditCard _creditCard; private…
catu
  • 888
  • 6
  • 24
0
votes
1 answer

Closing an SqlDataReader

I have an ASP.Net 2.0 Web Forms Application using SQL Server 2008. The application has a UI layer and Data Access Layer. I use Enterprise Libray 5.0 to persist the data. Recently my site has been running very slow, especially on pages where there…
tcode
  • 5,055
  • 19
  • 65
  • 124
0
votes
1 answer

Creating nicely formatted table in console with data from database

I want to output to my console a nicely formatted table with data from SqlDataReader. I found this answer here on SO with a nice class to do all the work, however, I need some help to implement the SqlDataReader part. My code for printing out the…
Frederik
  • 632
  • 4
  • 16
  • 34
0
votes
1 answer

losing data when transfering SqlDataReader object to the method that needs IDataReader interface

I have a method which needs a SqlDataReader object as parameter, and i have tests where i've mocked that object, and everything worked fine. But, now i need to change that method. It should now only call new method, which has a IDataReader as…
morel
  • 1
  • 1
0
votes
2 answers

SqlDataReader Convert SQL Signed to .NET Unsigned Integers

Often use SQL Identity as the ID of .NET objects. Start the ID at 0 or 1 as don't want the objects to have negative IDs. The ID is presented to users so it needs to be logical to humans. Also often use something like ((Int32)key1 << 32) + key2;…
paparazzo
  • 44,497
  • 23
  • 105
  • 176