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 and concurrency/deallocation issues

Running the below code is giving me an error: .NET Framework execution was aborted by escalation policy because of out of memory. System.InvalidOperationException: There is already an open DataReader associated with this Command which must be…
cdub
  • 24,555
  • 57
  • 174
  • 303
0
votes
1 answer

Reading data from database using labels and radio buttons

I am developing an online examination system, but im having difficulties trying to read questions from the database to be displayed on an aspx on page load. Please help me out...wat do i do...i tried this code but its not working well. string cs…
Shewn
  • 1
  • 1
  • 1
0
votes
1 answer

Data reader Display issue

Using c# with a windows form to read data from a data base. while (reader.Read()) { textbox1.Text += reader["Person"] + reader["Occur"].ToString() + "\n"; } Can somebody…
user1353517
  • 300
  • 3
  • 10
  • 28
0
votes
2 answers

How to use value selected by Sql Data Source in C# code

I am retrieving the email id of the user in SqlDataSource and want to send an email to this email ID. Below is the code for the SQL Data Source.
techblog
  • 529
  • 2
  • 5
  • 16
0
votes
1 answer

Is there a problem when I call SqlAdapter.Update and at the same time call SqlDataReader.Read

I have two applications, one updates a single table which has constant number of rows (128 rows) using SqlDataAdapter.Update method , and another application that select from this table periodically using SqlDataReader. sometimes the DataReader…
Ahmed
  • 7,148
  • 12
  • 57
  • 96
-1
votes
1 answer

how to use array as parameter in sqldatareader

I want to use array in sqldatareader object. Code for(int j=0;j<12;j++) //12 use for month { if(j!=(mon-1)) { ***String mont = MyReader1["('"+month[j]+"')"].ToString();*** tt += mont; } } I got error like 'January'…
user1162056
-1
votes
1 answer

Calling SQL Server stored procedure with result set and return value

Is there a way to get a dataset and a return value from a SQL Server stored procedure with just one execution of the stored procedure? Is there a way to get both in just one call? TIA Marcos Galvani SqlConnection conn = new…
-1
votes
1 answer

Running DataReader from separate class file in webforms c#

I placed my DB reader in a separate class file because I didn't want to keep rewriting it but I keep getting the error: Object reference not set to an instance of an object. db was null This is my DataReader: namespace ProjectName { public…
rlatmfrl
  • 17
  • 4
-1
votes
1 answer

sql(dr) is sending a missing result

I transfer the data I have taken from sql to the list, but it sends 1 missing data every time, the sql command works without any problems. works incorrectly in c# If there are 10 data in sql, it pulls 9 of them. SqlCommand komut = new…
-1
votes
1 answer

select query with where clause in ado.net using asp.net mv

this is my select query with where clause every time I call it the datatable is empty and list count is 0 please correct my select query or ado.net code. I want to get data from the SQL server from these parameters but I don't know my SQL query is…
-1
votes
2 answers

Update statement inside SqlDataReader loop not working

I am running the following code. Following code is giving error on executenonquery line inside my SQL DataReader loop runs. I am getting Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out I have tried…
Master
  • 1
  • 1
-1
votes
2 answers

.net Slow SqlDataReader

I am working with a WPF app which executes a stored procedure in SQL Server. The method Search queries a table and produces a result query that has more than 1000 rows and of an object type of Cliente. The query execution time is 19 seconds and the…
-1
votes
2 answers

How to Refresh the Datagridview using c#.net

i am creating a simple crud in c#.net.after add the record record will show on the datagridview itself. but i couldn't do it. code which tried so far i attched below. code sql = "insert into…
-1
votes
2 answers

copy DataReader data into a List

I am trying to load my custom object with Data coming from Data Reader..How can I accomplish that I can change the datareader to DATATable if it is better to use it Reader Data ID Description Type 1 Test1 1 2 Test2 2 3 …
rgoal
  • 1,236
  • 11
  • 35
  • 61
-1
votes
2 answers

SqlDataReader connection

In my windows service, I am executing a stored procedure that selects the top 2500 rows from a table and returns the data to the service. I am catching the results using the SqlDataReader object. My question is: does the SqlDataReader object return…
J Yang
  • 17
  • 2