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

return type of SqlDataReader method

I have a method inside a class, that contains SqlDataReader(it connects to a database table and retrieves a number of rows). later i want to assign each record that SqlDataReader has, to asp labels . but i don't know what should be the return type…
Iatrochemist
  • 256
  • 7
  • 19
0
votes
1 answer

What is the fastest and the most convenient way to map SqlDataReader rows to C# classes?

I am wondering what you consider as the best way to map SqlDataReader rows to corresponding C# classes. SQL-queries are generated dynamically.
Qué Padre
  • 2,005
  • 3
  • 24
  • 39
0
votes
3 answers

why I can't use two datareader in one procedure?

can you explain me why I can't use two datareader in on procedure? Here is the sample code: Private Sub Do_Execute() Dim conx as SqlConnection Dim cmd1 as SqlCommand Dim cmd2 as SqlCommand Dim drd1 as SqlDataReader Dim drd2 as…
RedsDevils
  • 1,413
  • 9
  • 26
  • 47
0
votes
2 answers

SqlDataReader filling column in datagridview

I have been wondering for quiet long time how can I set my SqlDataReader to fill column "pocet" in my datagridview "dtg_ksluzby". I thought that my code should look something like this: SqlCommand novyprikaz2 = new SqlCommand("SELECT pocet FROM…
Blaze M
  • 200
  • 4
  • 16
0
votes
1 answer

C# retrieve data from database - unknown datatype and unknown column name

I'm trying to retrieve user selected data from a database. The user can select up to five fields to show in a report and the fields are a mixture of strings, dates and numbers. I cannot convert the data to strings in the SQL code due to other…
KMBonin
  • 111
  • 4
  • 12
0
votes
3 answers

c#/sql-server, trying to get data to two ddl's from two tables...in one sqlDataReder

Well, i am tring to do something nice (nice for me, simple for you guys), i was told i can do it, but i have no idea where to start. I have two DDL's in a page, i need on page_load to popolate both, each one gets data from deferent table with no…
Erez
  • 5
  • 2
0
votes
1 answer

Stored Procedures reading a value of Min()

I am trying to find the minimum value of a primary key column of type (int) in a particular Table A portion of my Stored Procedure Code: IF NOT EXISTS ( SELECT * FROM Table ) BEGIN SELECT * FROM Table END ELSE BEGIN SELECT…
Ji yong
  • 433
  • 2
  • 5
  • 12
0
votes
1 answer

Making maskedtextbox to read NULL from SqlDataReader

I have this short code which I use to read data into maskedtextbox and then (which isn't part of this code) UPDATE them via SqlCommand SqlCommand novyprikaz = new SqlCommand("SELECT * FROM zajezd WHERE akce=" + tentoradek, spojeni); …
Marek
  • 3,555
  • 17
  • 74
  • 123
0
votes
1 answer

Check radiobuttons after SqlDataReader

I have 2 radio buttons in a panel and I save their value as numeric (0 and 1) here is the code for insert into SQL: String typdop="1"; if(rb_a.Checked)typdop="0"; ("INSERT INTO zajezd(typdop)values(@typdop") prikaz.Parameters.AddWithValue("typdop",…
Marek
  • 3,555
  • 17
  • 74
  • 123
0
votes
2 answers

SqlDataReader not recognizing column ordinal values

I'm trying to access a SQL database through a WCF service for a Silverlight application, and for some reason my SqlDataReader object keeps giving me errors. I'm only attempting to retrieve one single value from the database. This is my code right…
Kyle Breton
  • 361
  • 1
  • 5
  • 9
0
votes
1 answer

How many records a SQLiteDataReader or SqlDataReader can hold at a time?

I just want to know, Is there any size limit of SQLiteDataReader for holding records that mapped from Database? Is there any difference between SQLiteDataReader and SqlDataReader about size limit for holding records? Thanks in advance.
Rezoan
  • 1,745
  • 22
  • 51
0
votes
2 answers

SqlDataReader Read method not working

I am trying to retrieve column values from database here is my code protected void LoadProfile() { conn = new SqlConnection(connString); cmdProfile = new SqlCommand("SELECT Name, Father, Gender, UserName, City, Country, Department,…
user2517610
  • 275
  • 2
  • 8
  • 27
0
votes
2 answers

SqlDataReader returning incorrect results

I have an issue with this code in my MSSQL Data Access manager. Sometimes the returned records are not the expected ones. The DataReader columns come from the good table but the fields seems to become from another request. This behavior appears…
Alex
  • 1
  • 1
0
votes
5 answers

reading from a table that I dont know the table structure

I have a connection to a database view (SQL Server 2008 R2). But I don't know any of the columns. I need to select everything on that view. How can I do this by using SqlDataReader? SqlConnection con = new…
Tolga Evcimen
  • 7,112
  • 11
  • 58
  • 91
0
votes
1 answer

How to use PagedDataSource.CopyTo (or otherwise work with the same data I'm sending to my Repeater)

I'm populating a Repeater with a PagedDataSource and after I populate that Repeater, I want to perform some other operations on the subset of data that makes up the page I'm sending to the Repeater (my CurrentPageIndex, PageSize=10). So my question…
busse
  • 1,761
  • 14
  • 25