I am using a SQL Server database and C#. When retrieving data with a datareader, there are some fields that are null. What is the best way to handle a null value? In VB.Net, there was a single line test that would return an empty value if it was null, otherwise the non-null value would return. Here's some of the datareader code:
Thanks in advance for any help and examples!
HLeyes
var dr = myCMD.ExecuteReader(); while (dr.Read()) { ColumnItem colItem = new ColumnItem(); colItem.TABLE_CATALOG = dr["TABLE_CATALOG"].ToString(); colItem.TABLE_SCHEMA = dr["TABLE_SCHEMA"].ToString(); colItem.TABLE_NAME = dr["TABLE_NAME"].ToString(); colItem.COLUMN_NAME = dr["COLUMN_NAME"].ToString(); colItem.ORDINAL_POSITION = Convert.ToInt32(dr["ORDINAL_POSITION"]); colItem.COLUMN_DEFAULT = dr["COLUMN_DEFAULT"].ToString(); colItem.IS_NULLABLE = dr["IS_NULLABLE"].ToString(); colItem.DATA_TYPE = dr["DATA_TYPE"].ToString(); colItem.CHARACTER_MAXIMUM_LENGTH = Convert.ToInt32(dr["CHARACTER_MAXIMUM_LENGTH"]); colItem.CHARACTER_OCTET_LENGTH = Convert.ToInt32(dr["CHARACTER_OCTET_LENGTH"]);
Thanks in advance for any help and examples!
HLeyes