473,386 Members | 1,832 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.

DateTime Null Error, While assigning Null Date Value

pbala
37
Expand|Select|Wrap|Line Numbers
  1. ConnectionString = "....."
  2. QueryString = "SELECT * FROM SomeTable"
  3.  
  4. Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(ConnectionString)
  5. Dim myCommand As New MySql.Data.MySqlClient.MySqlCommand(QueryString, myConnection)
  6. Dim myReader As MySqlDataReader
  7.  
  8. Try
  9. myConnection.Open()
  10. myReader = myCommand.ExecuteReader
  11. Dim Field1,Field2 as String
  12. Dim Field3 as Datetime
  13. While myReader.Read
  14. Field1 = myReader.Item ("Field1")
  15. Field2 = myReader.Item ("Field2")
  16. Field3 = myReader.Item ("DateField")
  17. End While
  18.  
  19. 'Close the connection
  20. myReader.Close()
  21. myConnection.Close()
  22.  
  23. Catch exEvent As Exception
  24.  
  25. 'Do Something
  26.  
  27. End Try

Error Occured.... while DateField is Null in DataBase....
How do i set DateField to Null in my Code

thanks in advance,
Aug 10 '09 #1
1 3182
tlhintoq
3,525 Expert 2GB
Are you trying to send a null to the database?
Or are you asking how to react if you receive a null from the database?

Are you sure your database "DateField" is really of a type Datetime?
It could be the database is holding that value as a string and you need to parse it.

But you can't assign a null to a datetime. It is already a null if created without giving it a value. If you want to keep it a null, don't change it.
Aug 10 '09 #2

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

Similar topics

8
by: Manish Jain | last post by:
Platform : ASP.Net/C# void SomeFunction(DateTime date) { string text = date.ToString(); //This crashes if date is null } I am using a construct similar to above. I want to check if the date...
6
by: Paulb1us | last post by:
I want to set a DateTime field to Null before passing it to the DB //First I check to see if anything is in this datarow column, because sometimes we have no data. DateTime dt; if (...
2
by: Fred Nelson | last post by:
Hi: Another C# newby question: How do I declare a null DateTime variable: DateTime myDate = null; I get the error:
4
by: Curious | last post by:
Hi, I have a class that has some fields. One of the fields is of type DateTime. From the constructor of the class, I am passing DateTime.Now; The value being stored is the following:...
8
by: craigkenisston | last post by:
I have a generic function that receives a couple of datetime values to work with. They can or cannot have a value, therefore I wanted to use null. This function will call a database stored...
14
by: Bob Day | last post by:
using VS 2003, VB.net... Why is this valid: dim x as datetime = nothing but this is invalid: public sub DoSomething (Optional byval x as datetime = nothing) ....code to do something end...
2
by: Solution Seeker | last post by:
Hi, I need a solution to assign a Null to a Datetime Variable / Object. Am willing to know whether it is possible? I will appreciate you if any one knows the solution for it . The...
5
by: ns21 | last post by:
Our application is windows desktop application. We are using VS.Net 2003, C#, Framework 1.1, SQL 2000. We use webservices to add/update/select objects. We are using XML Serialization. Following is...
1
by: Brad Pears | last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field of type "smalldatetime". In my vb application, the user may or may not enter a date value into the appropriate text box....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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.