473,396 Members | 1,895 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,396 software developers and data experts.

best way to move a possibly null value into object from Db

I am using .NET 2.0 with this and have loaded a row into a data table... now
I want to move the info in that row into the fields of an object... what is
the best way to do this for fields that I know could be null... right now
say I have it set up like this

Object has fields
Private m_IsNotANull as string
private m_CouldBeNull as nullable(of datetime)

' now load row into this
m_IsNotANull = dt.row(0)("MyString").tostring
' ok this works easily, now how about null ones?
m_CouldBeNull = ???

I know I can check if the current value is null and do stuff like this

if dt.row(0)("CouldBeNullDate") isnot DBNull.value
m_CouldBeNull = diretcast(dt.row(0)("CouldBeNull"),datetime)
else
m_CouldBeNull = nothing
end if

but is that the easiest way to do it? what alternatives are out there?
thanks!
Jun 5 '07 #1
3 1299

"Smokey Grindle" <no****@nospam.comwrote in message
news:ul**************@TK2MSFTNGP03.phx.gbl...
>I am using .NET 2.0 with this and have loaded a row into a data table...
now I want to move the info in that row into the fields of an object...
what is the best way to do this for fields that I know could be null...
right now say I have it set up like this

Object has fields
Private m_IsNotANull as string
private m_CouldBeNull as nullable(of datetime)

' now load row into this
m_IsNotANull = dt.row(0)("MyString").tostring
' ok this works easily, now how about null ones?
m_CouldBeNull = ???

I know I can check if the current value is null and do stuff like this

if dt.row(0)("CouldBeNullDate") isnot DBNull.value
m_CouldBeNull = diretcast(dt.row(0)("CouldBeNull"),datetime)
else
m_CouldBeNull = nothing
end if

but is that the easiest way to do it? what alternatives are out there?
thanks!
You might be able to do this.
If Not IsDBNull(Object) Then

do not null

else

do is null

endif

Jun 5 '07 #2

An alternative would be to use the strongtype features of the datarow , and
so use the methods that are then automaticly provided to check for null
values or set null values

regards

Michel

"Smokey Grindle" <no****@nospam.comschreef in bericht
news:ul**************@TK2MSFTNGP03.phx.gbl...
>I am using .NET 2.0 with this and have loaded a row into a data table...
now I want to move the info in that row into the fields of an object...
what is the best way to do this for fields that I know could be null...
right now say I have it set up like this

Object has fields
Private m_IsNotANull as string
private m_CouldBeNull as nullable(of datetime)

' now load row into this
m_IsNotANull = dt.row(0)("MyString").tostring
' ok this works easily, now how about null ones?
m_CouldBeNull = ???

I know I can check if the current value is null and do stuff like this

if dt.row(0)("CouldBeNullDate") isnot DBNull.value
m_CouldBeNull = diretcast(dt.row(0)("CouldBeNull"),datetime)
else
m_CouldBeNull = nothing
end if

but is that the easiest way to do it? what alternatives are out there?
thanks!

Jun 6 '07 #3
Hi Michel,

From your answer I think that I understand the question (and answer). AFAIK
you can forever write any value to an object. I think that we miss it as
well, because here everything seems to be global declared, something I
seldom do certainly not in a sample because we don't know the types.

dim myObject as object = whatever typecasted thing

I think that we are looking more about what is asked than this simple
answer.

Cor

"Michel Posseth [MCP]" <MS**@posseth.comschreef in bericht
news:OT**************@TK2MSFTNGP05.phx.gbl...
>
An alternative would be to use the strongtype features of the datarow ,
and so use the methods that are then automaticly provided to check for
null values or set null values

regards

Michel

"Smokey Grindle" <no****@nospam.comschreef in bericht
news:ul**************@TK2MSFTNGP03.phx.gbl...
>>I am using .NET 2.0 with this and have loaded a row into a data table...
now I want to move the info in that row into the fields of an object...
what is the best way to do this for fields that I know could be null...
right now say I have it set up like this

Object has fields
Private m_IsNotANull as string
private m_CouldBeNull as nullable(of datetime)

' now load row into this
m_IsNotANull = dt.row(0)("MyString").tostring
' ok this works easily, now how about null ones?
m_CouldBeNull = ???

I know I can check if the current value is null and do stuff like this

if dt.row(0)("CouldBeNullDate") isnot DBNull.value
m_CouldBeNull = diretcast(dt.row(0)("CouldBeNull"),datetime)
else
m_CouldBeNull = nothing
end if

but is that the easiest way to do it? what alternatives are out there?
thanks!


Jun 6 '07 #4

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

Similar topics

136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Fr?d?ric Ledain | last post by:
Hi. I have to design new API, which some of them have to return a string. I have mixed feelings about the various strategies I can choose : 1. API(char *s, long *size) => the client gives a...
8
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
13
by: Martin Z | last post by:
I'm making a CRUD screen for an Oracle database... but problem is that the primary key in that table is populated via an autonumber, which in Oracle is done just with triggers and sequences. ...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
13
by: G | last post by:
Hello, Looking for opinions on a fairly simple task, new to ASP.net (C#) and want to make sure I do this as efficiently as possible. I have a web based form, and I need to run some SQL before...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
2
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi mister, I have an object with two properties, of type DateTime? (Nullable). Which is the best way for comparing ? The value of datetime can be null, and another value cannot be null, or two...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.