DateTime Null Error, While assigning Null Date Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbala
    New Member
    • Dec 2008
    • 37

    DateTime Null Error, While assigning Null Date Value

    Code:
    ConnectionString = "....."
    QueryString = "SELECT * FROM SomeTable"
    
    Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(ConnectionString)
    Dim myCommand As New MySql.Data.MySqlClient.MySqlCommand(QueryString, myConnection)
    Dim myReader As MySqlDataReader
    
    Try
    myConnection.Open()
    myReader = myCommand.ExecuteReader
    Dim Field1,Field2 as String
    Dim Field3 as Datetime
    While myReader.Read
    Field1 = myReader.Item ("Field1")
    Field2 = myReader.Item ("Field2")
    Field3 = myReader.Item ("DateField")
    End While
    
    'Close the connection
    myReader.Close()
    myConnection.Close()
    
    Catch exEvent As Exception
    
    'Do Something
    
    End Try

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

    thanks in advance,
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.

    Comment

    Working...