Null safe way to get values from an IDataReader
- by kumar
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