Null safe way to get values from an IDataReader

Posted by kumar on Stack Overflow See other posts from Stack Overflow or by kumar
Published on 2010-04-09T18:26:41Z Indexed on 2010/04/10 12:03 UTC
Read the original article Hit count: 597

Hi all,

(LocalVariable)ABC.string(Name)= (Idatareader)datareader.GetString(0);

this name value is coming from database.. what happening here is if this name value is null while reading it's throwing an exception?

I am manually doing some if condition here. I don't want to write a manual condition to check all my variables..

I am doing something like this now..

string abc =  (Idatareader)datareader.GetValue(0);
if(abc = null)
    //assiging null
else
    assiging abc value

is there something like can we write extension method for this? thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about extension-methods