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
2 answers

Sql Query error asp.net c#

I am using the below code to get results from my table and bind it to a gridview control . But I get the following error: "System.Data.SqlClient.SqlException: Incorrect syntax near 'x'" at "sqlda.Fill(ds1)". I am new to ASP.NET and cannot write good…
-1
votes
3 answers

Error: Invalid attempt to call Read when reader is closed after the while loop?

Hello i have a method which reads some data from the sql and saves them to arrays. to find out how many rows the sql result has i wrote this: DataTable dt = new DataTable(); dt.Load(rdr); count = dt.Rows.Count; after that,…
Eray Geveci
  • 1,099
  • 4
  • 17
  • 39
-1
votes
1 answer

I ask for the datetime value with dataReader and get the min value

I need your help to figure out and maybe solve this problem. I have a DataReader and when use the function GetDateTime, to read a Date column, I get the min value. I don't see a GetDate function. I tried changing the datatype of the column to…
Sterling Diaz
  • 3,789
  • 2
  • 31
  • 35
-1
votes
4 answers

Strange error when adding row to datatable

I'm hoping you guys can help me figure out why this is happening. I've been tearing my hair out trying to figure this out. Here's an example directly from my code (with the boring bits cut out) ...(Set up the connection and command, initialize a…
David W
  • 487
  • 2
  • 5
  • 12
-2
votes
2 answers

Reading all records from sqlite local file using c#

I am trying to read all the records from a local sqlite file. But for some reason, the code that I am using isn't reading all records. It is reading only the second row, that too only few columns, not all columns as well from that row. Below are the…
user243724
  • 13
  • 1
-2
votes
2 answers

SqlDataReader can only check for one of (Null or non null value)

I am writing a program (for personal use) that stores card names into a database. I want to implement a way to see if a name already exists and if it does it will go in a "Do_have_in_db_listbox" else it will go in a "do_not_have_list_box". This is…
Mr.Watson
  • 10
  • 3
-2
votes
1 answer

Trouble retrieving byte array image from database and display in picture box control

Please I am having some issues retrieving image of byte array from database into picture box in WPF page. This is my code to convert from byte to image: private BitmapImage GetBitmapImageFromBytes(byte[] bytes) { BitmapImage btm; …
DaPlug
  • 9
  • 4
-2
votes
1 answer

What makes SqlDataReader class in C# non-inheritable or non-Instantiable

There is an need to appreciate how C# has made SqlDataReader class Non Inheritable and Non Instantiable. Namespace: System.Data.SqlClient SqlDataReader class header : public class SqlDataReader : System.Data.Common.DbDataReader, IDisposable,…
-2
votes
1 answer

Refering to view values one by one

I have the following code which establishing an SQL connection inside of a project I am working on. What I want to do is to create a for loop which contains a method and every time the loop repeats the method runs with a different value until all…
banjo
  • 7
  • 3
-2
votes
1 answer

Get data from database and add it into text-box C# wpf

why I do not get anything in my textbox when I run the program? I have my methods in class can anybody give me any hint I can solve this issue. MainWin code *List cards = new List(); DBManager dB = new DBManager(); public…
Obaidi
  • 1
  • 3
-2
votes
1 answer

When files are selected repeatedly or files in Excel format, this exception is thrown

Either FileStream or Process, how can I figure it out? The following windows forms application first selects one or more files from openFileDialog1, checks to see if these files were in the database (GetInsertNummer), and writes them to the database…
sahb
  • 1
  • 4
-2
votes
1 answer

Getting error "Invalid attempt to read when no data is present" while reading the value of a column of database

While trying to read the value of a column, I am getting the error Invalid attempt to read when no data is present Code: If reader.HasRows Then name = reader("UserFirstName").ToString MsgBox(name) End If reader.HasRows is returning True, but…
-2
votes
2 answers

How to insert database value or string in mail body

I want to insert database content in Email body, index 0 of data reader which contain id number for each email address, I want to send mail using add id number in mail body for instance: The Employee id is 5. I need insert each id on each mail…
moonir01
  • 88
  • 1
  • 10
-2
votes
1 answer

System.InvalidOperationException: 'There is already an open DataReader associated with this Command which must be closed first.'

ps : i tried to close connexions and datareaders but it didn't work , also tried the previous solutions here but still got the error i even separed the connexions and it didn't work as well what i'm trying to do here is to read an id from a table…
mod money
  • 1
  • 2
-2
votes
2 answers

SQL data reader only reads the first row in VB.net

I have a database containing a table named restaurant. This table has columns named "time" and "tableno", and has 20 rows. I am using this code to read the data: Dim connString As String = "server=DESKTOP-69QA9LH\SQLEXPRESS; database=servicedb;…
Andrew Punio
  • 13
  • 1
  • 6