In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?
Dom 3 4200
Dom,
Yes, that is true. The SqlDataReader (or any class that derives from
DbDataReader, really) is meant for forward-only, read-only access.
If you want to move through a set of data, then you will need to load
the data into a DataTable, through a DbDataAdapter derivative (in this case,
SqlDataAdapter) and then you can cycle through the rows in any way that you
wish.
Mind you that doing it in this way is going to be the equivalent of
setting the cursor location on an ADODB Recordset to adUseClient, and then
loading the data statically (adOpenStatic). Basically, the DataTable is an
in-memory representation of the result set.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Dom" <do********@gma il.comwrote in message
news:21******** *************** ***********@e10 g2000prf.google groups.com...
In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?
Dom
Thanks for clarifying this. BTW, you've answered so many of my
questions, I feel like you're my private tutor.
Dom
On Dec 11, 1:28 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Dom,
Yes, that is true. The SqlDataReader (or any class that derives from
DbDataReader, really) is meant for forward-only, read-only access.
If you want to move through a set of data, then you will need to load
the data into a DataTable, through a DbDataAdapter derivative (in this case,
SqlDataAdapter) and then you can cycle through the rows in any way that you
wish.
Mind you that doing it in this way is going to be the equivalent of
setting the cursor location on an ADODB Recordset to adUseClient, and then
loading the data statically (adOpenStatic). Basically, the DataTable is an
in-memory representation of the result set.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
"Dom" <dolivas...@gma il.comwrote in message
news:21******** *************** ***********@e10 g2000prf.google groups.com...
In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?
Dom- Hide quoted text -
- Show quoted text -
Can I send you a bill? =) J/K
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Dom" <do********@gma il.comwrote in message
news:7d******** *************** ***********@t1g 2000pra.googleg roups.com...
Thanks for clarifying this. BTW, you've answered so many of my
questions, I feel like you're my private tutor.
Dom
On Dec 11, 1:28 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
>Dom,
Yes, that is true. The SqlDataReader (or any class that derives from DbDataReader , really) is meant for forward-only, read-only access.
If you want to move through a set of data, then you will need to load the data into a DataTable, through a DbDataAdapter derivative (in this case, SqlDataAdapter ) and then you can cycle through the rows in any way that you wish.
Mind you that doing it in this way is going to be the equivalent of setting the cursor location on an ADODB Recordset to adUseClient, and then loading the data statically (adOpenStatic). Basically, the DataTable is an in-memory representation of the result set.
-- - Nicholas Paldino [.NET/C# MVP] - m...@spam.guard .caspershouse.c om
"Dom" <dolivas...@gma il.comwrote in message
news:21******* *************** ************@e1 0g2000prf.googl egroups.com...
In the old days, using ADO, I used to be able to move up and down in a
resultset, but using functions like MoveNext, MoveFirst, MoveLast,
MovePrev. I don't see any of that in the SQLDataReader object. It
seems I can only move through it sequentially. Is that true?
Dom- Hide quoted text -
- Show quoted text -
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ricola ! |
last post by:
Why do I say:
SqlDataReader dr;
instead of
SqlDataReader dr = new SqlDataReader();
|
by: Franck Diastein |
last post by:
Hi, when I call ExportData I have this error:
Invalid attempt to Read when reader is closed.
Telling me that there's a problem with this line:
while(_dataR.Read()){
Code:
*************************************************
public void Export2CSV(){
|
by: Neil Guyette |
last post by:
Hello, Everyone,
I'm trying to find information on how to populate a combo
box using a SqlDataReader. I want to be able to set the
value of the combo's value property different then the
combo's text property (what the user will see). Is this
possible with a SqlDataReader?
Thanks
|
by: Arvind P Rangan |
last post by:
Hi All,
How do you get all the values of a sqldatareader if it
contains multiple resultset.
Using sqldatareader.nextresult and sqldatareader.read
e.g.
While sqldatareader.read '
If not sqldatareader then
sqldatareader.nextresult
|
by: Michael Carr |
last post by:
I have a function that populates a class with values from a database. I'd
like to pass into the function either a SqlDataReader or a DataRow,
depending on which mechanism I'm using to retrieve data from the database.
However, the two classes don't appear to have any common interfaces that
would allow me to enumerate the fields. Yet, when you databind you can pass
either of these classes (as well as many others) and .NET somehow knows how...
| |
by: me |
last post by:
Why is SqlDataReader not present in visual studios Toolbox->Data where
I find components like DataSet? Most examples in books and in vs.net
are based on datasets but using disconnected tables seems a bit
heavyweight for most purposes. I there some particular reason to stay
away from sqldatareader??
I have managed to bind components using sqldatareader but digging up
the
information was quite hard.
|
by: bidllc |
last post by:
I have a funtion that works fine and dandy when called from anywhere in my
app. It will NOT work when called from inside the class in which it resides.
This is the function I'm calling: "getProductByID(productID)" from inside
another method in the same class. See below.
This line throws a null ref exception:
While dr.Read()
Thanks for any insight!
|
by: mimi |
last post by:
Hi
Please help me out, I can't find a way to close a sqldatareader when error
occur at statement cmd.ExecuteReader(). I can't close it in catch because
it is local in try scope and I can't declare it outside try scope either
since we have to call cmd.executeReader to create sqldatareader
public string GetLogs(int logID)
{
|
by: Web learner |
last post by:
I am trying to create a method GetDataFor(string column) becaues I have to repeat the same statements for several columns but I get an error as follows:
The name 'dr' does not exist in the current context
It seems the dr -the instance of sqlDataReader - is not becoming available to the method. How to make it available? This seems trivial and newbie problem related to OOP, but I am confused. Could you pl. look at the code or point me to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |