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
-1
votes
1 answer

Update table using check null value from data reader

My two columne email and status on tableemail i had use a data reader for count mail address and send mail: > OleDbCommand cmd = null; > OleDbCommand cmd2 = null; > > string queryString = "select email,status…
brids
  • 25
  • 2
  • 11
-1
votes
2 answers

c# sqldatareader no data

I have little problem here. I try to use SqlDataReader to read data from my database. Code is like this: internal static User GetUser(string login) { SqlConnection conn = new SqlConnection(DataBaseUtility.ConnectionString); …
-1
votes
3 answers

C# read int value from SQL Server database

I'm trying to read QuaInMagazine (int value) from a SQL Server database. This is part of code: sqlCon.Open(); using (SqlCommand sqlComm = new SqlCommand("Select QuaInMagazine from tbl_Parts2 where Name = '" + Name_txt.Text + "' and Number='" +…
WG97
  • 52
  • 1
  • 2
  • 6
-1
votes
1 answer

I want to ask that, can I iterate through a SqlDataReader. and display its values in single textbox one row after another?

protected void Button1_Click(object sender, EventArgs e) { SqlConnection MyConnection = new SqlConnection("Data Source=VIJAYSTIWARI\\SQLEXPRESS;Initial Catalog=earthquake;User ID=sa;Password=HereIsPwd;"); MyConnection.Open(); …
-1
votes
1 answer

Read coordinates from geography SQL datatype to SqlDataReader in C#

I've searched around and I've seen you can access the latitude with myGeography.Lat but it doesn't seem to work when trying to read to sqldatareader, this is what I'm trying: String sql = "SELECT * FROM myTable WHERE…
-1
votes
3 answers

Data reader already open

Have already looked questions similar to mine but none of them works for me this is my code dbconn = New SqlConnection dbconn.ConnectionString = ("Data Source=JENELIE\SQLEXPRESS;Initial Catalog=feeding_monitoring_system;User…
Jhaze
  • 33
  • 6
-1
votes
1 answer

Working with large data set using SqlDataReader

I have some code that fetches relatively large amounts of data from my SQL db (approx 200k records, 7 columns) which I then have to act upon and update / insert into other tables. My initial iteration is done by opening a SqlDataReader and looping…
chilluk
  • 217
  • 2
  • 17
-1
votes
1 answer

Getting error when trying to use sqlclient.sqldatareader?

I am getting error saying that my syntax is incorrect however everything looks fine to me. On the line where datareader is used it says that there is incorrect syntax at the word "And". I have tried numerous changes to try make it work with no…
Danny James
  • 244
  • 3
  • 16
-1
votes
1 answer

Convert SQLDataReader results to JSON, with nested JSON objects

I have a C# application which retrieves an SQL result set in the following format: customer_id date_registered date_last_purchase loyalty_points 1 2017-01-01 2017-05-02 51 2 2017-01-23 …
user2181948
  • 1,646
  • 3
  • 33
  • 60
-1
votes
1 answer

Iterating through List of Query Parameters and binding results to Gridview using DataReader and Datatable

I have a list of query parameters(selected items from checklistbox). I need to pass each parameter to a query(sql server select statement) and bind results to grid view. I am trying to add rows to datatable using datareader. Can some one please…
tmk
  • 1
-1
votes
2 answers

Exporting SqlDataReader results to array in C#

I've written a function that that runs a SQL query, and have exposed it to Excel with ExcelDNA. The query itself uses a SqlDataAdapter and its corresponding .Fill() method to populate a DataTable. I then iterate over the rows and columns of the…
insomniac
  • 192
  • 1
  • 3
  • 16
-1
votes
1 answer

SqlDataReader performance

I have a performance issue with SqlDataReader. It seems that the bottleneck is reading large string rows (some values are about 2Kb). It takes 20 minutes to read 5000 rows whereas the same query executes in SSMS in less than 20 seconds and returns…
Random
  • 3,807
  • 2
  • 30
  • 49
-1
votes
3 answers

Reading in list using SqlDataReader C#

I have to fill in some lists in while loop as: while (_myReader_1.Read()) { _Row_Counter++; int _authorID = _myReader_1.GetInt32(0); Author _author = _eAthors.FirstOrDefault(_a => _a._AuthorID == _authorID); if (_author == null) { …
maliks
  • 1,102
  • 3
  • 18
  • 42
-1
votes
2 answers

C# reader is closed while reading?

I am running a C# windows application, and I get an error message when trying to use a datareader. The error message is: "Invalid attempt to call CheckDataIsReady when reader is closed." I used stop point and saw that the code works fine until it…
Nimrod Yanai
  • 777
  • 2
  • 8
  • 30
-1
votes
1 answer

Display data to View using SqlDataReader in MVC

How to display data using Razor view using SqlDataReader in MVC? I have tried something like this. Controller code:- public ActionResult UserDetails(DashBoard dash) { using (var cn = new…
Vivek Pandey
  • 21
  • 1
  • 1