How to Check Null for records returned?
ASP.NET
2
Posts
2
Posters
0
Views
1
Watching
-
Hi, When i try to try to use the ExecuteScalar method, e.g. myValue = cmd.ExecuteScalar(), I get an error when the result is null. How can i avoid this? rgds, Nickson
wrap the ExecuteScalar method call in a try/catch and take appropriate actions if an exception is caught (in the case of no record returned) If you mean that you get an error when you try to do something with myValue, you can check to see if it is null:
if(myValue != DBNull.Value) { etc. }
RabidK