I am new to C#. I was executing some select queries from database tables using System.Data.SqlClient classes. I got sqlnullvalueexception while executing some select query.
The code you posted is fine. You could also do something like that :
value = r[n] as string;
If the value in the database is null, r[n] will return DBNull.Value, and the cast to string will return null.
r[n]
string
null