Re: retrieving just one row based on the primary key

Tech-Archive recommends: Fix windows errors by optimizing your registry



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







.



Relevant Pages

  • Re: Replication on 2 SQLCE
    ... Please reply only to the newsgroup so that others can benefit. ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ...
    (microsoft.public.sqlserver.ce)
  • Re: What are OleDbParameter names with Original_ prefix?
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... Since the table has a primary key column, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: is it possible to mark my CLR function as UNSAFE in code or visual studio anywhere so that wehn
    ... Please reply only to the newsgroup so that others can benefit. ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ADO.NET Transaction
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... Client transactions put too much schema-dependent, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Performance problems with OracleDataReader
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... referencing the columns by ordinal is far faster than using strings. ...
    (microsoft.public.dotnet.framework.adonet)