473,396 Members | 1,838 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.

How to trap null value

Hi All,

I have a datagrid which has few columns that are of the datetime type. I wanted to format these columns so that it will only display the date. The code below works fine when there is dates in the sql database, however it prompts an error if the field is null.. Please help..

Private Sub dgRecords_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgRecords.ItemDataBound

Dim str10 As String = e.Item.Cells(10).Text.Trim
Dim str11 As String = e.Item.Cells(11).Text.Trim

If e.Item.ItemType = ListItemType.AlternatingItem Or _
e.Item.ItemType = ListItemType.Item Then

If e.Item.Cells(10).Text <> "1/01/1900 12:00:00 AM" Then
e.Item.Cells(10).Text = str10.Substring(0, 10)
Else
e.Item.Cells(10).Text = " "
End If

If e.Item.Cells(11).Text <> "1/01/1900 12:00:00 AM" Then
e.Item.Cells(11).Text = str11.Substring(0, 10)
Else
e.Item.Cells(11).Text = " "
End If
End If
End Sub
Oct 3 '06 #1
5 3891
radcaesar
759 Expert 512MB
Whats the DB u r using?

Is it SQLServer or Access.

Since the column is DateTime type, Set ssome default value if u have no problem.

Set the Required field to NO (Access). I Thought that Allow NULL is not available here.

How did u get the date from the user ? Using DateTime Picker?
Oct 3 '06 #2
Whats the DB u r using?

Is it SQLServer or Access.

Since the column is DateTime type, Set ssome default value if u have no problem.

Set the Required field to NO (Access). I Thought that Allow NULL is not available here.

How did u get the date from the user ? Using DateTime Picker?
Hi!

I'm using sql database. I didn't use DateTimePicker, instead i use a textbox for user input and a compare validator to validate the 'date' format.

I got the solution d.. The code is as below..

If e.Item.Cells(18).Text <> "1/01/1900 12:00:00 AM" _
And e.Item.Cells(18).Text <> "&nbsp;" Then
e.Item.Cells(18).Text = str18.Substring(0, 10)
Else
e.Item.Cells(18).Text = " "
End If

The trick is that, you have to trap an empty space in datagrid using the html format and not " " or Null or DBNull..

Neway thanks for sharing...
Oct 6 '06 #3
When I run a query and assign database values to members in a class I do the following

foreach(DataRow dr in dr.Rows)
{
strProperty =
Convert.ToString
(
(dr[0] == DBNull.Value)
?""
:dr[0].ToString()
);
}

I hope this helps!
Oct 6 '06 #4
Sorry, didn't notice your syntax is VB
Oct 6 '06 #5
cadaha
2
Hi

This is what I use:

If Not IsDBNull(dataField) Then
'do something
else
'do something else
end if

Regards

Carl
Oct 6 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bob Darlington | last post by:
When a user clears a value from a combo box (by pressing the delete key), the following message appears: "You tried to assign the null value to a variable that is not a variant data type". ...
11
by: pemo | last post by:
Ambiguous? I have a student who's asked me to explain the following std text (esp. the footnote). 6.2.6.1.5 Certain object representations need not represent a value of the object type. If...
10
by: pemo | last post by:
As far as I understand it, a trap representation means something like - an uninitialised automatic variable might /implicitly/ hold a bit-pattern that, if read, *might* cause a 'trap' (I'm not...
6
by: temper3243 | last post by:
Hi Can someone explain me what is happening below ? Why is it printing 401380 $ cat scanf.c #include<stdio.h> int main() { int i; scanf(" %d",&i);
17
by: Army1987 | last post by:
If uMyInt_t is an unsigned integral type, is the following a necessary and sufficient condition that uMyInt_t has no trap representation? (uMyInt_t)(-1) >CHAR_BIT*sizeof(uMyInt_t)-1 That is,...
10
by: Richard Tobin | last post by:
May all-bits-zero be a trap representation for a pointer? What if I calloc() space for a structure containing pointers? -- Richard -- "Consideration shall be given to the need for as many as...
2
by: Linda Liu[MSFT] | last post by:
Hi George, Keyboard input introduces the idea of focus. In Windows, a particular element is designated as having the focus, meaning that it acts as the target for keyboard input. The user sets...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
I have to read data from an Excel Sheet. Using Microsoft Office Interop and Automation I create an Excel object Dim xl As New Excel.Application, wkbk As Excel.Workbook, rng as Excel.Range I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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
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.