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

How do I avoid duplication of columns in a Gridview when using code-behind to execute sql query?

I have a sql query that I execute in code behind that returns data several rows long and multiple columns wide. I have a GridView on my aspx page, where I mention only certain columns because I want to either change the display name of the column,…
Freakishly
  • 1,533
  • 5
  • 32
  • 61
0
votes
2 answers

SqlDataReader does not return all records

I am experiencing a problem with ADO.NET SqlDataReader. When I run underlying stored procedure directly in SSMS - it returns 1.7 million of records. When I run a related VB.NET code that fills an ADO.NET DataTable - I also get 1.7 million of…
Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
0
votes
2 answers

Passing Integer values to SqlParameter in .net

i want to pass integer value to the SqlParameter which is executing an SqlDataReader, but when i pass integer value it says, the Parameter is not supplied, below is my code: Common SqlDataReader Function public static SqlDataReader…
Abbas
  • 4,948
  • 31
  • 95
  • 161
0
votes
4 answers

SqDataReader closed issue in .net

i have created a function which executes query and returns SqlDataReader, now i am using that in another function work with the returned data, but i gets the error saying reader is already closed. here is the functions: public static SqlDataReader…
Abbas
  • 4,948
  • 31
  • 95
  • 161
0
votes
1 answer

dynamic html table with column span and row span in vb.net

If I have a value from sqlDataReader as below: | YEAR1 | NAM1 | CRDT1 | SEMER1 | YEAR2 | NAM2 | CRDT2 | SEMER2 | ----------------------------------------------------------------------- | 1 | Name1 | 1 | 1 | 1 | Name10 | …
Pengan
  • 1,813
  • 4
  • 15
  • 16
0
votes
3 answers

Retrieve Datareader using Objects

I have worked on retrieving the data from SQL database using Datareader and populate it in Datatable.. But, I am wondering whether is there any way to handle the data from datareader without using datatable ? I mean- handling the table values using…
Bharathi
  • 1,015
  • 13
  • 41
0
votes
1 answer

ExecuteReader: is using statement enough?

I'm using a web service, that is invoked every few ms, to expose some functionalities. Basically these functionalities are based on store procedures, and all my methods look like the follow: [WebMethod] public bool CheckMessageForMES( out int…
ff8mania
  • 1,553
  • 3
  • 19
  • 28
0
votes
1 answer

Loading data into labels with DataReader where unsure of total rows in query result

How would you write the code to read the data from a query and display each row in a separate label if you don't know how many rows the query result may contain? If you try to read one too many rows with the DataReader, it throws an excetion when…
0
votes
1 answer

SQLDataReader connection close

How to define rule in stylecop to force developer to close SQLDataReader() or connection? if there exists any other solution then also please suggest. The solution required is to force developer to close sqldatareader or we can do any other…
Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
0
votes
1 answer

SqlDataReader dbnull values

I have a question about SqlDataReader: Is there some way to modificated the values in SqlDataReader? For example: while (sdr.Read()) { double PRICE = double.Parse(sdr["PRICE"].ToString()); if (PRICE == null) PRICE = Single.MinValue; …
Xavi Guirao
  • 338
  • 4
  • 17
0
votes
1 answer

records count from database

I have 8 tabs containing number of records in each one and a function that should count the number of records in each tab and put it in the tab’s header name like the following: public void count_records(object sender, EventArgs e) { …
Kemoid
  • 45
  • 2
  • 2
  • 7
0
votes
1 answer

Why is this not working? Does not execute code?

I am trying to have a textBox auto complete with values from a database. When i bullet test the code will walk though until the if statement in the function below. Could some one please tell me why my code wont execute after that if? I am trying to…
Pomster
  • 14,567
  • 55
  • 128
  • 204
0
votes
2 answers

Populate a List and DataGridView with contents of an SqlDataReader

I am trying to write a function that can take three parameters: an SqlDataReader, a DataGridView and a List. I want to take the contents of the SqlDataReader and create a list of Objects, then bind this to the DataGridView. With a few pointers from…
amarsha4
  • 453
  • 6
  • 21
0
votes
3 answers

What is the meaning of the following line of code?

I am learning ADO.NET and now I am trying to understand the SqlDataReader. I am trying to learning by using this tutorial and I am facing some difficulties now in understanding the following part of the code mentioned HERE: while (rdr.Read()) { …
user1395782
  • 107
  • 3
  • 17
0
votes
3 answers

It don't get any data from DataReader

i work with N tiers tec in C# for ado, trying to make it easy to use and capable to change any database kind with out write all the cod all over again , my code here doesn't get any error but it doesn't get any values to my textbox (i am trying to…
Marwan
  • 31
  • 8