[Solved] How to avoid Tostring exception if string is null? [duplicate]


I guess you are reading from data reader.

You will have to check if the value is null or DBNull and then you can call to string method.

    string user_guid = dr["user_guid"] != DBNull.Value && dr["user_guid"] != null ? dr["user_guid"].ToString() : null ; 

Hope this helps.

solved How to avoid Tostring exception if string is null? [duplicate]