I've been trying to load an INT from my SQL-Server DB into my C# application and convert it into string.
Basically, it's the ID/Primary key of the DB Table that I want to use as string. This is what I do :
string Variable_ID;
Variable_ID = HandleDBNull(reader, "ID");
and I get a IndexOutOfRange exception.
Here is the HandleDBNullfunction :
private string HandleDBNull(SqlDataReader r, string columnName)
{
if (!r.IsDBNull(r.GetOrdinal(columnName)))
return r[columnName].ToString();
else
return String.Empty;
}
It works for the string columns so there seems to be something wrong with the conversion. I've already tried Convert.ToString and got the same error.
Any ideas?
isDBNullis a bad method-name. It suggests that it returns abool.