Thread: cast problem
View Single Post
 
Old September 6th, 2004, 09:40 AM
Jeff Mason Jeff Mason is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

There are several things wrong with your code.

If no rows meet your selection criteria when the query executes, the database will return a NULL value. This is not the string "NULL", but rather a special (object) value represented by the constant system.dbnull.value.

The ExecuteScalar method returns a value of type object which you must cast to the appropriate type.

The CInt() function converts its argument to an integer. You are attempting to convert the string "chk" to an integer, which won't work and will generate an invalid cast exception.


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com