Connecting Tech Pros Worldwide Help | Site Map

DateTime Null Error, While assigning Null Date Value

pbala's Avatar
Member
 
Join Date: Dec 2008
Location: Tamil Nadu
Posts: 34
#1: Aug 10 '09
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,
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,761
#2: Aug 10 '09

re: DateTime Null Error, While assigning Null Date Value


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.
Reply