Newbie question regarding finding unique records in ado.net

  • Thread starter Thread starter Stefan Johansson
  • Start date Start date
S

Stefan Johansson

Hi all,

Which is the best way to retrieve i row/record by a
unique key (sql with param, some method in ado.net that I
haven't yet discovered?)

Thanks in advance

Stefan
 
Execute a SELECT query that has a WHERE clause that specifies a match on the
PK?

SELECT mycol, mycol2 FROM mytable WHERE pkID = @IDWanted




--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
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.
__________________________________
 
If I undestand you correctly, use a Sql/Oledb DataReader. If you want just
one value, you can use command.ExecuteScalar (which still uses a DataReader
but only sends back one value)

For SqlParameters there are tons of examples out there.

Basically instead of SELECT * FROM MyTable WHere Job = '" & someJOb & "'"
You'd use
"SELECT * FROM MyTable Where Job = @Job"
Then you'd add a Parameter to your command object.

myCOmmand.Parameters.Add("@Job", someJOb)

There are multiple overloads for it, my example is a simple one, but if you
search for SqlParameter, there are many examples.

HTH,

Bill
 
Back
Top