473,795 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Null Values in ItemUpdating Event

I have a DetailsView control and when it get's updated i send an email
containing the new details. I have used the ItemUpdating event handler for
the DetailsView and i am populating the MailMessage.Bod y property with a
string variable which i build up using something like

String strMessageBody = "Field1 = " + e.NewValues["Field1"].ToString() +
"\nField2 = " + e.NewValues["Field1"].ToString();

This works fine apart from when one of the fields i am refering to is blank.
What i expected to happen is the e.NewValues["Field1"].ToString would give
me a blank string. However it seems that if the value coming from the
DetailsView is null for Field1 then e.NewValues["Field1"] doesn't exist.

Is there an easy way round this, i am putting the values of about 10 fields
into one string variable, i want to avoid 10

if (e.NewValues["Field1"] != null)
{
strMessageBody = strMessageBody + "Field1 = " +
e.NewValues["Field1"].toString();
}
May 25 '06 #1
3 3423
If you just want to avoid duplicated code, why not move it into another
method?

public string getField(IOrder edDictionary values, string key)
{
return values.Contains Key(key) ?
string.Format(" {0} = {1}", key, values[key]) :
string.Empty;
}

then it's a simple case of string strMessageBody = getField("field 1") +
getField("field 2")...

May 25 '06 #2
It's not so much code duplication i am tring to avoid as having to do a load
of comparisons to see if a particular value is set or not. The problem with
passing e.NewValues("So meField") to a function/method is that if SomeField is
set to null in the DetailsViews control then rather than there being
e.NewValues("So meField") with a value of null, it simply does not exist. You
get a "Object reference not set to an instance of an object" if you try to do
something such as e.NewValues("So meField").ToStr ing().
"Flinky Wisty Pomm" wrote:
If you just want to avoid duplicated code, why not move it into another
method?

public string getField(IOrder edDictionary values, string key)
{
return values.Contains Key(key) ?
string.Format(" {0} = {1}", key, values[key]) :
string.Empty;
}

then it's a simple case of string strMessageBody = getField("field 1") +
getField("field 2")...

May 25 '06 #3
I have solved the problem, you simply set ConvertEmptyStr ingToNull="Fals e",
in all of the TemplateFields of the DetailsView.

"clickon" wrote:
It's not so much code duplication i am tring to avoid as having to do a load
of comparisons to see if a particular value is set or not. The problem with
passing e.NewValues("So meField") to a function/method is that if SomeField is
set to null in the DetailsViews control then rather than there being
e.NewValues("So meField") with a value of null, it simply does not exist. You
get a "Object reference not set to an instance of an object" if you try to do
something such as e.NewValues("So meField").ToStr ing().
"Flinky Wisty Pomm" wrote:
If you just want to avoid duplicated code, why not move it into another
method?

public string getField(IOrder edDictionary values, string key)
{
return values.Contains Key(key) ?
string.Format(" {0} = {1}", key, values[key]) :
string.Empty;
}

then it's a simple case of string strMessageBody = getField("field 1") +
getField("field 2")...

May 25 '06 #4

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

Similar topics

1
3056
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding filtering/formatting the data, upon inserting $var into
26
45452
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.) How can I achieve this? I suppose I would get the most-hated "table/view is changing, trigger/function may not see it" error if I tried to write a trigger that checks the uniqueness of non-null values upon insert/update.
1
2434
by: Ben Reese | last post by:
When you bind a text box to a field that contains null values the text box displays an empty string. Great! My Database field is an integer and I want an empty text box to represent a NULL value. However the EndEdit event on the datarow returns the error The input string was in an incorrect format I have failed to find a way to either trap the empty string in the rowchanging event and turn it into DBNULL or to programatically...
8
12558
by: manning_news | last post by:
Using SQL2000. According to Books Online, the avg aggregrate function ignores null values. ((3+3+3+3+Null)/5) predictably returns Null. Is there a function to ignore the Null entry, adjust the divisor, and return a value of 3? For example:((3+3+3+3)/4) after ignoring Null entry. If there's more than one null value, then adjust divisor accordingly. For example: ((5+5+5+4+Null+5+5+Null)/8) would be ((5+5+5+4+5+5)/6) after nulls...
3
4015
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append query will not work unless there are values in the data i am attempting to send. I want the fields in the destination table to accept null and populated values. Any help here would be gladly accepted. thanks
6
5950
by: doncee | last post by:
I have a list box that is generated on a form by way of a Parameter Query. Problem is whenever I try to refer to the list box, i.e., to update the underlying table, I am getting a "null" value from any row or field I refer to. Have tried using "after update" events as well as a button click event to no avail. The debug window always shows "null" values when I bring it up while trying to examine my code\events. Is there a way to get back to...
0
3550
by: =?iso-8859-2?Q?=A3ukasz_Led=F3chowski?= | last post by:
Hi! I am using FormView with SqlDataSource. The problem is that during ItemUpdating event of FormView, NewValues table is empty. OldValues has all values of fields bound on template. What can be the reason? -- £ukasz Ledóchowski GG: 503647 lukled@tlen.pl
2
2371
by: Matt MacDonald | last post by:
Hi all, I'm having an issue that's driving me crazy. I have a datatable that I need to display all the information for on a page. So, instead of manually coding every single column to a label, I decided it would be easier and safer to use a formview to display it all, bound to an objectdatasource. Sounds simple enough. The problem is that many of my fields could potentially have null values, which produces an error similar to the...
1
4076
by: deepakthegeek | last post by:
I have a listview control in which I had replaced all the ItemTemplate labels with TextBoxs. I also have a command button on the page, when the button is clicked I am able to retreive the text in all the TextBoxes one by one by running a For..next loop. After reading the textboxes content I want to fire the ItemUpdating event for each row so that I can update all the rows at once. I have the following code in the button_click event, but it...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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,...
0
10213
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 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...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
agi2029
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...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.