Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executescalar() method - check for zero rows

Status
Not open for further replies.

DotNetGnat

Programmer
Joined
Mar 10, 2005
Messages
5,548
Location
IN
Hi guys...

i am doing something like this...(below is a dummy code)

int val;
sql = "Select field1 from mytable where Id = 2 ";
---
---
val = (int)dbCmd.ExecuteScalar();

works fine and i get the val if the record exists...but what if the record doesnt exist...i mean how to check for the zero rows using ExecuteScalar??

am i missing something simple here...

-DNG
 
Run it and see what happens. I would assume the value "va" would be NULL.

Jim
 
i tried this...

if (val == NULL)
{
val = -1;
}

doesnt seem to work...

-DNG
 
ok i got it working...

object val;

val = dbCmd.ExecuteScalar();

if (val !=null) --> works...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top