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

Question about checking for Nulls

I have a text box on a form “txtExamDate” that I know contains nothing. I am
trying to test code that will determine the text box is nothing. I am
getting the error because there is no value in the field and I am assigning
it to a date field. My question is: How do I get the If statement to work?

Exception Details: System.FormatException: String was not recognized as a
valid DateTime

Line 723: If TypeOf txtExamDate.Text Is DBNull Then
Line 724: Else
Line 725: patientRow.ExamDate =
DateTime.Parse(txtExamDate.Text)
Line 726: End If

Source File: c:\inetpub\wwwroot\STD\Patient_Detail.aspx.vb Line: 725

Oct 24 '05 #1
3 1464
Change the If condition to:

If (txtExamDate.Text.Trim() = "") Then
'Text box empty
Else
' DateTime parsing...
End If

"JackO" <Ja***@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
I have a text box on a form "txtExamDate" that I know contains nothing. I
am
trying to test code that will determine the text box is nothing. I am
getting the error because there is no value in the field and I am assigning
it to a date field. My question is: How do I get the If statement to work?

Exception Details: System.FormatException: String was not recognized as a
valid DateTime

Line 723: If TypeOf txtExamDate.Text Is DBNull Then
Line 724: Else
Line 725: patientRow.ExamDate =
DateTime.Parse(txtExamDate.Text)
Line 726: End If

Source File: c:\inetpub\wwwroot\STD\Patient_Detail.aspx.vb Line: 725
Oct 24 '05 #2
a text box (web or form) will never contain DBNull.Value which is used when
checking for Database nulls.

Compair to string.Empty or for a length of 0.

-Andrew

"JackO" <Ja***@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
I have a text box on a form "txtExamDate" that I know contains nothing. I
am
trying to test code that will determine the text box is nothing. I am
getting the error because there is no value in the field and I am
assigning
it to a date field. My question is: How do I get the If statement to
work?

Exception Details: System.FormatException: String was not recognized as a
valid DateTime

Line 723: If TypeOf txtExamDate.Text Is DBNull Then
Line 724: Else
Line 725: patientRow.ExamDate =
DateTime.Parse(txtExamDate.Text)
Line 726: End If

Source File: c:\inetpub\wwwroot\STD\Patient_Detail.aspx.vb Line: 725

Oct 24 '05 #3
Hi Jacko,

I don't know your requirement but why don't you use RequiredFieldValidator
control when we have it for such a problem.

I think it is the best solution for your problem.

Thanks,
Bhavesh Patel,
Software Engineer,
Ahmedabad-India.
"JackO" wrote:
I have a text box on a form “txtExamDate” that I know contains nothing. I am
trying to test code that will determine the text box is nothing. I am
getting the error because there is no value in the field and I am assigning
it to a date field. My question is: How do I get the If statement to work?

Exception Details: System.FormatException: String was not recognized as a
valid DateTime

Line 723: If TypeOf txtExamDate.Text Is DBNull Then
Line 724: Else
Line 725: patientRow.ExamDate =
DateTime.Parse(txtExamDate.Text)
Line 726: End If

Source File: c:\inetpub\wwwroot\STD\Patient_Detail.aspx.vb Line: 725

Oct 25 '05 #4

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

Similar topics

3
by: A.M. de Jong | last post by:
Reading a lot about Nulls right now I still can't find a Technical reason to use it or not. For what I've understand is this: In an Ingres database a Null column has a standard extra storage...
6
by: mike | last post by:
I'm doing what I thought was a simple GROUP BY summary of fairly simple data and the my numbers aren't working out Some results are showing up <NULL> when I know the data is in the database ...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
3
by: JackO | last post by:
I have a text box on a form “txtExamDate” that I know contains nothing. I am trying to test code that will determine the text box is nothing. I am getting the error because there is no value...
3
by: Brett Romero | last post by:
What is a better way for checking nulls than using the "==" operator? For example, .Equals() is better than == for most operations since it knows the type being checked. However, it doesn't seem...
3
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
5
by: Analizer1 | last post by:
Hello again... Im using XMl/xsl to generate text report from a service getting data to xml from sqlserver 2005 xml generates ok but when xslCompiledTransform runs i get a...
0
by: ricardovillarroel | last post by:
i am trying to check the text box for nulls once the user tabs over the text box. i do not want it to check for nulls when i click on okay. here is code. do i need to setfocus so it will go back to...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...

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.