M
Mike J
below is a code snuppet of a table server class i wrote
this the best way to return default values for null from a datatable or is
there a better way....
still learning all the net framwork
tia
MJ
public object ColumnGet(string cname)
{
//type thistype;
// thistype = this.Table.Rows[iRow][cname].GetType();
object uRow = this.Table.Rows[iRow][cname];
System.TypeCode utype = System.Type.GetTypeCode(GetType());
//this.Table.Rows[iRow][cname].GetType());
if (utype.GetType() == typeof(System.DBNull))
{
//if (this.TreatNullAsType)
//{
return dvNulls.DefaultTypeValue(uRow);
//this.Table.Columns[cname].DataType);
//}
}
return uRow; // this.Table.Rows[iRow][cname];
//supporting static class
public static class dvNulls
{
public static object DefaultTypeValue(object uValue)
{
if (uValue ==typeof(System.String))
{
return "";
}
else if (uValue == typeof(int))
{
return 0;
}
else if (uValue == typeof(System.Boolean))
{
return false;
}
else if (uValue == typeof(System.DateTime))
{
return new DateTime(0);
}
return null;
}
}
this the best way to return default values for null from a datatable or is
there a better way....
still learning all the net framwork
tia
MJ
public object ColumnGet(string cname)
{
//type thistype;
// thistype = this.Table.Rows[iRow][cname].GetType();
object uRow = this.Table.Rows[iRow][cname];
System.TypeCode utype = System.Type.GetTypeCode(GetType());
//this.Table.Rows[iRow][cname].GetType());
if (utype.GetType() == typeof(System.DBNull))
{
//if (this.TreatNullAsType)
//{
return dvNulls.DefaultTypeValue(uRow);
//this.Table.Columns[cname].DataType);
//}
}
return uRow; // this.Table.Rows[iRow][cname];
//supporting static class
public static class dvNulls
{
public static object DefaultTypeValue(object uValue)
{
if (uValue ==typeof(System.String))
{
return "";
}
else if (uValue == typeof(int))
{
return 0;
}
else if (uValue == typeof(System.Boolean))
{
return false;
}
else if (uValue == typeof(System.DateTime))
{
return new DateTime(0);
}
return null;
}
}