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

class data add will rewrite the data already exists

I have a class and in 2 foreach loop I want to add all the data in tables in my dataset to my class but the problem is that: after it finishes the inner foreach loop, the next table that is going to be copied will also replace the records already in…
lol
  • 93
  • 3
  • 11
-1
votes
2 answers

Error filter the table based on a date field

i use this code to filter table by date field (in table) this my code : public double Mounthcost() { DateTime today = DateTime.Now; PersianCalendar persianCalendar = new PersianCalendar(); int yearPersian =…
ghasem deh
  • 698
  • 1
  • 10
  • 26
-1
votes
1 answer

The rectangle didn't draw through SQLDataReader while clause

Why the rectangle didn't draw? Is there any mistake in my code? I try to create a rectangle through SQLDataReader while clause.. private void PrintsDoc (object sender, PrintPageEventArgs e) { Graphics g = e.Graphics; StringFormat sf = new…
Hobas Matius
  • 61
  • 2
  • 13
-1
votes
1 answer

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index while fetch data using Sqldatareader

Currently I am getting an error when attempting to fetch data using SqlDataReader and the parameter is in list i.e. on newcmd.Parameters.Add("@frmcat", res[i]); Here is my code SqlDataAdapter adpt = new SqlDataAdapter("SELECT DISTINCT TOP 5…
Chetan Naik
  • 151
  • 13
-1
votes
1 answer

SqlDataReader prints multiple rows, how can I split?

I want to retrieve data from a DB using a SqlDataReader. I got it working but my query return more than one row of data and I want to separate it. Here is my code string query = "select title, rating, dor from movie where title like…
Craig
  • 364
  • 1
  • 3
  • 25
-1
votes
1 answer

The SqlParameter is already contained by another SqlParameterCollection.3

This is my first question: The SqlParameter is already contained by another SqlParameterCollection. SqlDataReader rdr[0] vs. object brings me table columns values. public ArrayList[] GetInfo(string sqlCommand, SqlParameter sqlParameter) …
hikmet_anil
  • 89
  • 3
  • 14
-1
votes
1 answer

SQL SELECT protocol in C#

I've tried searching StackOverflow but the query returns a lot of unrelated results and I did spend time looking elsewhere before posting. I am writing an app in C# / ASP.NET and would like to pull just the Full Names and id from the database of…
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
-1
votes
2 answers

Fetch row and Save in Variable

I am writing a WPF C# application and I want to save fetched row in a variable. SqlDataAdapter connAdp = new SqlDataAdapter("SELECT * FROM users WHERE (username = '"+uname+"') AND (password = '"+pass+"');",conn); SqlDataReader fetchInfo =…
-1
votes
2 answers

passing a string to a class

I have a problem with my SQL datareader, i want to make an external class and make the code in my xaml.cs as short as possible, because there are a lot of sqldatareaders needed in my program. for this I want to pass following two strings to the…
maxim
  • 1
  • 2
-1
votes
2 answers

how to read SQL column for a row, by specifying the column name, in Visual Basic ASP.NET Web Application project

I have a table in a SQL Server 2008 database. How can I read a row's column value by specifying the column name in a SqlDataReader after doing a SELECT * FROM table WHERE ? The error is: "Additional information: Invalid attempt to…
Doug Null
  • 7,989
  • 15
  • 69
  • 148
-1
votes
1 answer

How to wrap SqlDataReader with IObservable properly?

I would like to explore the possibility to use IObservable as a wrapper around a SqlDataReader. Until now we were using the reader to avoid materializing the entire result in the memory and we did so using blocking synchronous API. Now we want to…
mark
  • 59,016
  • 79
  • 296
  • 580
-1
votes
1 answer

Select sql how to get value DataReader

I want to retrieve value /miejsca/, but I don't how it works. For example please show me how selecting value define as variable or how to show it in textbox. At this point I recieve "System.Data.SqlClient.SqlDataReader" in textbox. …
-1
votes
1 answer

SqlDataReader InvalidOperationException

I have a SqlDB.dll that has the function: public SqlDataReader getEnumValues(int enumId) { SqlDataReader reader = null; using (SqlConnection connection = new SqlConnection(connectionString)) { …
Yogevnn
  • 1,430
  • 2
  • 18
  • 37
-1
votes
1 answer

Retrieve Data from database in C#.net

Good day!, I want to retrieve data from my database the user will input in the text box and when the user click the search button it will display in the form but when I execute the code below nothing will happen. Can anyone help me. namespace…
user3278908
  • 445
  • 1
  • 4
  • 8
-1
votes
3 answers

How to get how many element datareader has read?

How to get the length of a datareader, something like: sqlDataReader dr = command.ExecuteReader(); dr.Read(); int L= dr.Length;// this doesn't work. ?
Aan
  • 12,247
  • 36
  • 89
  • 150