Solved

Conversion e.keys from type 'DBNull' to type 'Integer' is not valid on e.keys(0)

Posted on 2013-02-07
2
340 Views
Last Modified: 2013-02-07
Hi,

I am getting the following error when the selectedID is Nothing, how can I fix that?

Conversion e.keys from type 'DBNull' to type 'Integer' is not valid.
0
Comment
Question by:JessyRobinson1234
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 275 total points
ID: 38863139
you have FIRST to check of the value is DBNull.Value before trying to convert it.
or make sure the value is not dbnull.value in the first place, but always a "integer" value.

if ( e.keys(0) != DBNull.Value) 
{
  // do the cast as needed
}
else
{
  // value is null... what to do here?
} 

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38863146
simply check selectedID for DB.Null before assign to your integer variable
if IsDBNull(selectedID ) then
''do something 
end if

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now