Hi,
I am looking for opinions and alternatives for handling
null values in a data object which reads a record from a
database table.
This object will have properties which will be populated
from the DB table columns, standard enough. But what
about the instance where a column could be null.
The strategy I have used before is to assign a known
value to a property where the DB column is null
(Integer.Minval ue for a property of type integer).
The object then knows that the property is really null
when the DB is being updated from the object,
Has anyone any better pattern for doing this, or
alternate design strategies,
Brendan 8 2207
If you are using stored procedures you can use the isnull
() MSSql method.
isnull(name,"") as kundenr, -----Original Message----- Hi,
I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table.
This object will have properties which will be populated from the DB table columns, standard enough. But what about the instance where a column could be null.
The strategy I have used before is to assign a known value to a property where the DB column is null (Integer.Minva lue for a property of type integer). The object then knows that the property is really null when the DB is being updated from the object,
Has anyone any better pattern for doing this, or alternate design strategies,
Brendan .
If you are using stored procedures you can use the isnull
() MSSql method.
isnull(name,"") as kundenr, -----Original Message----- Hi,
I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table.
This object will have properties which will be populated from the DB table columns, standard enough. But what about the instance where a column could be null.
The strategy I have used before is to assign a known value to a property where the DB column is null (Integer.Minva lue for a property of type integer). The object then knows that the property is really null when the DB is being updated from the object,
Has anyone any better pattern for doing this, or alternate design strategies,
Brendan .
So you would essentialy replace the null value with a
default value like integer properties are assigned 0 or
Integer.minvalu e and when you are going to the database
convert this back to null when adding it to the stored
procedure param list.
B. -----Original Message----- If you are using stored procedures you can use the isnull () MSSql method.
isnull(name,"" ) as kundenr, -----Original Message----- Hi,
I am looking for opinions and alternatives for handling null values in a data object which reads a record from
adatabase table.
This object will have properties which will be
populatedfrom the DB table columns, standard enough. But what about the instance where a column could be null.
The strategy I have used before is to assign a known value to a property where the DB column is null (Integer.Minv alue for a property of type integer). The object then knows that the property is really null when the DB is being updated from the object,
Has anyone any better pattern for doing this, or alternate design strategies,
Brendan . .
So you would essentialy replace the null value with a
default value like integer properties are assigned 0 or
Integer.minvalu e and when you are going to the database
convert this back to null when adding it to the stored
procedure param list.
B. -----Original Message----- If you are using stored procedures you can use the isnull () MSSql method.
isnull(name,"" ) as kundenr, -----Original Message----- Hi,
I am looking for opinions and alternatives for handling null values in a data object which reads a record from
adatabase table.
This object will have properties which will be
populatedfrom the DB table columns, standard enough. But what about the instance where a column could be null.
The strategy I have used before is to assign a known value to a property where the DB column is null (Integer.Minv alue for a property of type integer). The object then knows that the property is really null when the DB is being updated from the object,
Has anyone any better pattern for doing this, or alternate design strategies,
Brendan . .
Try this
When setting the object properties
If IsDBNull(Fields (i)) The
obj.Properties( i)=Nothin
Els
obj.Properties( i)=Fields(i
End I
When saving the changes to the DB
If obj.Properties( i)=Nothing The
Fields(i)=Syste m.DBNull.Valu
Els
Fields(i)=obj.P roperties(i
End I
Hope it works for you.
Try this
When setting the object properties
If IsDBNull(Fields (i)) The
obj.Properties( i)=Nothin
Els
obj.Properties( i)=Fields(i
End I
When saving the changes to the DB
If obj.Properties( i)=Nothing The
Fields(i)=Syste m.DBNull.Valu
Els
Fields(i)=obj.P roperties(i
End I
Hope it works for you.
I have always tended to use 2 properties for this and populate private
variables as well. This works then for databinding also. When accessing the
value, simply test the IsNull property before retrieving the actual.
private int foreignKey = 0;
private bool foreignKeyIsNul l = false;
public int ForeignKey {
get {return this.foreignKey ;}
set {this.foreignKe y = value;}
}
public bool ForeignKeyIsNul l {
get {return this.foreignKey IsNull;}
set {this.foreignKe yIsNull = value;}
}
private void Scatter(dataRow row) {
if (!(foreignKeyIs Null = (dataRow["ForeignKey "].Value == DBNull.Value)))
this.foreignKey = (int)dataRow[ForeignKey"].Value;
}
private void Gather(dataRow row) {
if (this.foreignKe yIsNull)
dataRow["ForeignKey "].Value = DBNull.Value;
else
dataRow["ForeignKey "].Value = this.foreignKey ;
}
"Brendan McLoughlin" <br************ ****@gmaccm.com > wrote in message
news:12******** *************** ******@phx.gbl. .. Hi,
I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table.
This object will have properties which will be populated from the DB table columns, standard enough. But what about the instance where a column could be null.
The strategy I have used before is to assign a known value to a property where the DB column is null (Integer.Minval ue for a property of type integer). The object then knows that the property is really null when the DB is being updated from the object,
Has anyone any better pattern for doing this, or alternate design strategies,
Brendan
I have always tended to use 2 properties for this and populate private
variables as well. This works then for databinding also. When accessing the
value, simply test the IsNull property before retrieving the actual.
private int foreignKey = 0;
private bool foreignKeyIsNul l = false;
public int ForeignKey {
get {return this.foreignKey ;}
set {this.foreignKe y = value;}
}
public bool ForeignKeyIsNul l {
get {return this.foreignKey IsNull;}
set {this.foreignKe yIsNull = value;}
}
private void Scatter(dataRow row) {
if (!(foreignKeyIs Null = (dataRow["ForeignKey "].Value == DBNull.Value)))
this.foreignKey = (int)dataRow[ForeignKey"].Value;
}
private void Gather(dataRow row) {
if (this.foreignKe yIsNull)
dataRow["ForeignKey "].Value = DBNull.Value;
else
dataRow["ForeignKey "].Value = this.foreignKey ;
}
"Brendan McLoughlin" <br************ ****@gmaccm.com > wrote in message
news:12******** *************** ******@phx.gbl. .. Hi,
I am looking for opinions and alternatives for handling null values in a data object which reads a record from a database table.
This object will have properties which will be populated from the DB table columns, standard enough. But what about the instance where a column could be null.
The strategy I have used before is to assign a known value to a property where the DB column is null (Integer.Minval ue for a property of type integer). The object then knows that the property is really null when the DB is being updated from the object,
Has anyone any better pattern for doing this, or alternate design strategies,
Brendan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brendan McLoughlin |
last post by:
Hi,
I am looking for opinions and alternatives for handling
null values in a data object which reads a record from a
database table.
This object will have properties which will be populated
from the DB table columns, standard enough. But what
about the instance where a column could be null.
|
by: xAvailx |
last post by:
I have a requirement that requires detection of rows deleted/updated by
other processes. My business objects call stored procedures to create,
read, update, delete data in a SQL Server 2000 data store. I've done
a fair amount of research on concurrency handling in newsgroups and
other resources. Below is what I've come up as a standard for
handling concurrency thru stored procedures. I am sharing with everyone
so I can get some comments...
|
by: farseer |
last post by:
Here is the scenario:
I have an interface which defines get methods for data that will make
up a row in a table. However, the source of this data may, over time,
switch/change (The company may choose to change data providers).
Therefore i thought to myself, a type of Adapter Pattern is best here
and so i proceeded with that. here's an example of what i did (note
this implementation differs from the text book one due to the way data...
|
by: Hasan O. Zavalsiz |
last post by:
Hi , i am trying to figure out which approach is better to use .
let me explain the scenario.
i am using the "Nortwind" database . in this database i have "Customers "
table .The following is the two different ways to handle this table.
CASE 1 :
create a struct that encaplusates table "Customers" columns
public struct structCustomers
{
public string CustomerID;
|
by: Gaensh |
last post by:
HI,
I have a singleton pattern to acess my database the following is
the sample code use to implement singleton pattern
public class DataAccessHelper
{
private static DataAccessHelper instance;
/// <summary>
/// public property that can only get the single instance of this
class.
/// </summary>
| |
by: Eric |
last post by:
I am implementing a variation on the Singleton design pattern, that
allows up to 8 objects of a class to be instantiated, and returns a
null pointer for anything more than 8.
I am running into a compile problem with GNU g++.
Here is the code:
/******************** FILE sample.h ********************/
|
by: Steven Nagy |
last post by:
So I was needing some extra power from my enums and implemented the
typesafe enum pattern.
And it got me to thinking... why should I EVER use standard enums?
There's now a nice little code snippet that I wrote today that gives me
an instant implementation of the pattern. I could easily just always
use such an implementation instead of a standard enum, so I wanted to
know what you experts all thought.
Is there a case for standard enums?
|
by: dustin |
last post by:
I've been hacking away on this PEP for a while, and there has been some
related discussion on python-dev that went into the PEP:
http://mail.python.org/pipermail/python-dev/2007-February/070921.html
http://mail.python.org/pipermail/python-dev/2007-February/071155.html
http://mail.python.org/pipermail/python-dev/2007-February/071181.html
I'd love to have feedback on this PEP:
- from a user's perspective (would you want to write...
|
by: Mohamed Mansour |
last post by:
Hello,
What is the purpose of implementing the Observer Pattern if we can trigger
an event easily?
For example (from books),
You have a "Forecaster" which notifies "Observable" when a prediction is
ready, then there is a "WeatherViewer" which calls methods from the
"Observer Interface".
|
by: richard.markiewicz |
last post by:
Hi Gurus,
Working with a .NET 2 C# web application. Using
System.DirectoryServices a lot to read information from AD. There
seemed to be several bugs in the .NET 1.1 implementation of that DLL
and out of habit I now very aggressively dispose of objects when I'm
done with them.
Is there anything wrong with this pattern:
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |