473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

default types

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;
}
}
May 11 '07 #1
2 1332
Your code snippt is difficult to follow, but if I understand what you're
doing, then I might write it like this:

public object ColumnGet(string cname)
{
object value = this.Table.Rows[iRow][cname];
if (value == System.DBNull.Value)
value = GetDefaultValueByType(this.Table.Columns[cname].DataType);

return value;
}

public static object GetDefaultValueByType(System.Type type)
{
if (type == typeof(bool))
return false;
else if (type == typeof(string))
return "";
//etc.
else
return null;
}

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets
"Mike J" <ve***********@sbcglobal.netwrote in message
news:s3*****************@newssvr23.news.prodigy.ne t...
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;
}
}

May 12 '07 #2
thanks much
MJ

"Brian Schwartz" <ow***@fishnetcomponentswos.comwrote in message
news:e1**************@TK2MSFTNGP05.phx.gbl...
Your code snippt is difficult to follow, but if I understand what you're
doing, then I might write it like this:

public object ColumnGet(string cname)
{
object value = this.Table.Rows[iRow][cname];
if (value == System.DBNull.Value)
value = GetDefaultValueByType(this.Table.Columns[cname].DataType);

return value;
}

public static object GetDefaultValueByType(System.Type type)
{
if (type == typeof(bool))
return false;
else if (type == typeof(string))
return "";
//etc.
else
return null;
}

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets
"Mike J" <ve***********@sbcglobal.netwrote in message
news:s3*****************@newssvr23.news.prodigy.ne t...
>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;
}
}


May 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
9
by: Pierre Senellart | last post by:
The C++ standard states (26.3.2.1), about std::valarray constructors: > explicit valarray(size_t); > > The array created by this constructor has a length equal to the value of > the argument....
29
by: John Wood | last post by:
Even though CSC does its best to detect use of unassigned variables, it often misses it... for example if you just declare a double in a class without assigning a default value, it has a default...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
12
by: Edward Diener | last post by:
Given value class X { public: // Not allowed: X():i(100000),s(10000) { } // Allowed void InitializeDefaults() { i = 100000; s = 10000; } private: int i;
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
7
by: =?Utf-8?B?Y291Z2FyaXN0aWM=?= | last post by:
I am trying to convert an C# application to VB and have one issue which is converting the generic value to the default. C# uses return default(T) as the return value how would I translate this in...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.