I have the following code:
| String name; if (rdr.GetString(rdr.GetOrdinal("NAME")) == null) name = ""; else name = rdr.GetString(rdr.GetOrdinal("NAME")); |
and i'm getting an error message "Data is null.This method or property cannot be called on Null Values."
Any ideas why i'm getting this error message?
Thank you in advance.
Jisss shyamPosted Oct 21, 2009, 5:49 AM
you can use reader in another way also
rdr[0] OR rdr["Name"]
thanks
DealyPosted Oct 13, 2009, 1:47 AM
rdr is SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection) that connects to a stored procedure.
The rdr is not empty because i get values in other fields. The only field in the db that is null is NAME and i get this error message. (NAME is nullable field in the db)
rdr.GetString should be empty in some cases, but instead of getting an error message i want to get empty string.
I used the following but i'm wondering if there is a better way to do that.
Thank you in advance.
Roei BarPosted Oct 7, 2009, 11:13 AM
you code is not totaly explained, you need to explain what are the objects
but i belive that the rdr is either empty or rdr.GetString is empty or something like that, and this is why you get the NULL issue
Danatas GerviPosted Oct 7, 2009, 9:44 AM