default types
- From: "Mike J" <vettes_n_jets@xxxxxxxxxxxxx>
- Date: Fri, 11 May 2007 16:34:01 -0700
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;
}
}
.
- Follow-Ups:
- Re: default types
- From: Brian Schwartz
- Re: default types
- Prev by Date: passing reference variable!!. out bug?
- Next by Date: Re: passing reference variable!!. out bug?
- Previous by thread: passing reference variable!!. out bug?
- Next by thread: Re: default types
- Index(es):