Selecting one record from SQL CE table

  • Thread starter Thread starter David
  • Start date Start date
D

David

What is an optimal way for selecting one record from SQL CE table?
For example I want to get record which ID=7 and fill some textboxes with
data from this record.

Also how can I check if there is no records selected at all?
 
Hi David,

Use SqlCeCommand object's ExecuteScalar method and you can retrieve a single
record using that.

Regarding checking whether any data has been returned or not, there's a
IsDBNull method, which returns a boolean indicating record return status.

This is available with SqlCeDataReader object.

HTH,
Asheesh
 
You can only get "the first column of the first row in the result set" using
ExecuteScalar. Use ExecuteReader to get an entire row of data.

If you want to see if a record exists, you can use ExecuteScalar with
"SELECT COUNT(*) FROM ... WHERE ..." to see how many rows match the criteria
you specify.
 
Back
Top