Solved

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

Posted on 2013-02-07
2
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 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