C# Programming
01-26-2010, 05:11 AM
I am trying to set an integer variable to null if no vaue but it's not accepting? how can I set the variable to null if the value in the database is null?
This is what I am trying:
if (sql_reader["company_id"] != null)
company_id = Convert.ToInt32(sql_reader["company_id"]);
else
company_id = null;
and this is what I am getting:
Cannot convert null to 'int' because it is a non-nullable value type
I also tried DBNull.Value but getting:
Cannot implicitly convert type 'System.DBNull' to 'int'
This is what I am trying:
if (sql_reader["company_id"] != null)
company_id = Convert.ToInt32(sql_reader["company_id"]);
else
company_id = null;
and this is what I am getting:
Cannot convert null to 'int' because it is a non-nullable value type
I also tried DBNull.Value but getting:
Cannot implicitly convert type 'System.DBNull' to 'int'