Re: retrieving just one row based on the primary key
- From: "William \(Bill\) Vaughn" <billvaRemoveThis@xxxxxxxxxx>
- Date: Thu, 28 Dec 2006 10:57:17 -0800
Sure there is.
SELECT stuff FROM MyTable WHERE myPKColumn = @PKColumnValue
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
"Fred Exley" <fexley221@xxxxxxx> wrote in message
news:12p6tbulkv6lv3d@xxxxxxxxxxxxxxxxxxxxx
Thanks much, everybody. Apparently the 'preferred way' depends on what
one is trying to do, but there is no 'get the one and only record for
these PK values' method in existence (yet). -Fred
"William (Bill) Vaughn" <billvaRemoveThis@xxxxxxxxxx> wrote in message
news:e7hSGcjKHHA.5000@xxxxxxxxxxxxxxxxxxxxxxx
The Command object has a number of "execute" methods. While ExecuteScalar
can fetch a single value, ExecuteReader can be programmed to only process
the first row if you set the CommandBehavior.SingleRow option. However,
if more than one row is returned by the SELECT, these are discarded by
ADO.NET.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
"Fred Exley" <fexley221@xxxxxxx> wrote in message
news:12p3p9sd323k6e2@xxxxxxxxxxxxxxxxxxxxx
Is there a preferred way to obtain one row of data based on the PK? I
can retrieve the record onto my C# app using a dataset or datareader,
but then I have to loop thru this result set even though I know there
will always be either zero or one row retrieved. Isn't there a more
elegant way to address this common need? thanks
.
- Follow-Ups:
- Re: retrieving just one row based on the primary key
- From: Otis Mukinfus
- Re: retrieving just one row based on the primary key
- From: Fred Exley
- Re: retrieving just one row based on the primary key
- References:
- retrieving just one row based on the primary key
- From: Fred Exley
- Re: retrieving just one row based on the primary key
- From: William \(Bill\) Vaughn
- retrieving just one row based on the primary key
- Prev by Date: Re: SqlBulkCopy
- Next by Date: Re: retrieving just one row based on the primary key
- Previous by thread: Re: retrieving just one row based on the primary key
- Next by thread: Re: retrieving just one row based on the primary key
- Index(es):
Relevant Pages
|