I am returning an integer list from a datacolumn. This particular column is (int,null). But I got an exception.
Specified cast is not valid.
Code:
public List <int> GetSortOrder(DataTable dt,string columnName)
{
List<int> Orders = new List<int>();
foreach (DataRow row in dt.Rows)
{
Orders.Add((int)row[columnName]);
}
return Orders;
}
What I want is if it is null, then forcing it as 0. Should I use nullable type int? or just simply using if ... else...?