0

I'm trying to handle null values coming from a database column (which has either int or null)

I wrote this code :

int? nullInt = null; 
int? typeTwo = myReader.IsDBNull(myReader["Type2"]) ? nullInt : (int)myReader["Type2"];

But I get this error :

The best overloaded method match for 'System.Data.Common.DbDataReader.IsDBNull(int)' has some invalid arguments Can you tell me how to fix this? Thanks.

1 Answer 1

1

Looks like IsDBNull accepts ìnt as a parameter. You can get the number of your Type2 column with GetOrdinal method like;

myReader.IsDBNull(myReader.GetOrdinal("Type2"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.