Hi, I am looking for the recommended way to retrieve several values
from a single record, i.e. a typical lookup scenario. An example would
be a query that needs to retrieve user_name, user_addres, user_email
for a given user.
I know that if I had to get a single values I should use the
Command.Execute Scalar() and that if I need to get several records I
should use the SqlDataReader and loop using its Read() method.
But how should I retrieve multiple values from a single record?
Thank you for your help.
ilZoro. 6 1832
One route is ExecuteNonQuery using variables / parameters for the items
Marc
Either do Read() once or follow Marc's suggestion.
--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
"zoro" <il****@gmail.c om> wrote in message
news:11******** *************@u 72g2000cwu.goog legroups.com... Hi, I am looking for the recommended way to retrieve several values from a single record, i.e. a typical lookup scenario. An example would be a query that needs to retrieve user_name, user_addres, user_email for a given user. I know that if I had to get a single values I should use the Command.Execute Scalar() and that if I need to get several records I should use the SqlDataReader and loop using its Read() method. But how should I retrieve multiple values from a single record? Thank you for your help. ilZoro.
Thanks Marc, Miha. So far i did both but felt there must be a 'proper'
way to do it, built in the ADO.NET architecture - just like
ExecuteScalar() . Perhaps ExecuteRecord() ?
"zoro" wrote: Thanks Marc, Miha. So far i did both but felt there must be a 'proper' way to do it, built in the ADO.NET architecture - just like ExecuteScalar() . Perhaps ExecuteRecord() ?
I think there may be some confusion. SqlDataReader.R ead() returns a record
for each row returned by your query. Just call SqlDataReader.G etString(x) (or
which ever method maps to the appropriate data type), replacing x with either
the field ordinal returned by SqlDataReader.G etOrdinal("fiel dName"), or the
name of the field you want.
Thanks Dan. You are right of course to say that what I'm trying to
achieve can be achieved in several other ways. I suppose what I am
trying to say is that if ADO.NET provides a special way to retrieve a
single value with ExecuteScalar() (even though you could achieve this
task using SqlDataReader), in order to handle a popular type of query,
it stands to reason it would also provide a special way to do this
common task too.
zoro wrote:
[...snip...] if ADO.NET provides a special way to retrieve a single value with ExecuteScalar() (even though you could achieve this task using SqlDataReader), in order to handle a popular type of query, it stands to reason it would also provide a special way to do this common task too.
If you select a scalar, you'd not expect anything else except a single
value. If you do a "select * from table where condition = true", it's very
likely the result will have more than one row (even though you might be sute
it will contain one row only). Since you cannot know in advance the number
of rows your query will return, there is no sense in having some method
returning one row only... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: andreas.maurer1971 |
last post by:
Hi all,
since a few years I use the following statement to find duplicate
entries in a table:
SELECT t1.id, t2.id,...
FROM table AS t1 INNER JOIN table AS t2
ON t1.field = t2.field
WHERE t1.id < t2.id
|
by: Neil |
last post by:
I need to get two values from a complex SQL statement which returns a single
record and use those two values to update a single record in a table. In
order to assign those two values to variables and then use those variables
in the UPDATE statement, I created a cursor and used Fetch Next.... Into.
This way, I only have to call the complex SQL once instead of twice.
This seems like the best way to go. However, I've always used cursors for...
|
by: Mark Feller |
last post by:
I want to provide users a page where they can browse entries in a database
10 at a time, for example. I am doing this as a table, where each row is a
database entry. I want to be able to give the user the ability to modify
entries. By either clicking on a link or a button on each row, I want the
user to be sent to another page to edit that entry.
What is the best way to track which entry the user is wanting to edit?
Thanks for...
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to use.
The above URL is version 1.0 (draft) that resulted. IMO, it is not a
replacement for the FAQ,...
|
by: Robin S. |
last post by:
More clueless newbie questions...
Table 1: "available specs"
Table 2: "classes"
A single form shows a single record from the table "classes". Each record in
"classes" may contain several records from "available specs" (and several
fields from each of those records).
| |
by: Chris Uwins |
last post by:
Hi there, i know theres a number of ways I can achieve this but want
to know the best, (but still quite simple).
Up until a year ago I never used Access but have designed a few
databases for work. I am working on Access 2000.
I have basic SQL/VB skills - and am pretty accomplished at putting the
databases together.
Anyway...I've created a database to keep track of "Dayworks" we are
|
by: kev |
last post by:
Hi all,
I have created a database for equipments. I have a form to register the
equipment meaning filling in all the particulars (ID, serial, type,
location etc). I have two buttons at the end of the form which is
submit and cancel. After i have clicked submit, the information is
stored directly into my corresponding database table. My problem here
is i need to retrieve back the information submitted to display all the
data that the...
|
by: kamsmartx |
last post by:
I'm new to programming and need some help figuring out an algorithm.
I need to design some kind of algorithm which will help us define capacity for one of our portfolios....here's the problem explained (also see attached example):
1. The graph defines total capacity, y-axis being $, x-axis being date/time. the bars on the graph represent individual items.
2. What I need to do is place the items on the graph in an optimized manner,...
|
by: trullock |
last post by:
Hi,
Can anyone suggest the best way to go about the following...
I'm tracking clicks (mouse down x,y coordinates) on a web page by
using some javascript to create an XHR which sends the coordinates to
a recording service, such as:
/Record.ashx?X=123&Y=456
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |