Solved

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

Posted on 2013-02-07
2
344 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jquery + C#.net radiobuttonlist 3 30
VB.NET Textbox input validation 4 37
SSRS Deployment problem 5 64
How to repeat the data 4 17
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

839 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