Conversion from string "" to type 'Date' is not valid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abby1
    New Member
    • Feb 2012
    • 12

    #1

    Conversion from string "" to type 'Date' is not valid

    Hello i am only getting this error everytime i try to update/edit data on a web form. the error is, Conversion from string "" to type 'Date' is not valid. can someone assist me please thanks. The Add form to this is working i even went over the Date field to ensure it is correct because from searching on the internet they referred to the Date field, but on the edit form this error is only popping up. please help!!
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    To make things easier for all, post the code you're using and whats causing this error. Without seeing what and how you're doing this it's just a shot in the dark.

    Comment

    • abby1
      New Member
      • Feb 2012
      • 12

      #3
      Code:
      Protected Sub Find_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Find.Click
      
      
      
              Dim Department_ID As String = txtDepartmentID.Text
              Dim Sequence_ID As String = txtSequenceID.Text
              Dim Date_Requested As String = txtDateRequested.Text
              Dim _GET_FileTransacUpdate As New Records_Mgmt_BLL.FileTransac
              Dim key As DataRow = _GET_FileTransacUpdate.GET_FileTransacUpDate(Department_ID, Sequence_ID, Date_Requested)
      
      
      
              If IsDBNull(key(0)) Then
                  txtDepartmentID.Text = ""
              Else
                  txtDepartmentID.Text = key(0)
              End If
      
              If IsDBNull(key(1)) Then
                  txtSequenceID.Text = "0"
              Else
                  txtSequenceID.Text = key(1)
              End If
      
              If IsDBNull(key(2)) Then
                  txtRequestingOfficer.Text = ""
              Else
                  txtRequestingOfficer.Text = key(2)
              End If
      
              If IsDBNull(key(3)) Then
                  txtDateRequested.Text = "1/1/2012"
              Else
                  txtDateRequested.Text = key(3)
              End If
      
              If IsDBNull(key(4)) Then
                  txtDateSent.Text = "1/1/2012"
              Else
                  txtDateSent.Text = key(4)
              End If
      
              If IsDBNull(key(5)) Then
                  txtDateReturned.Text = "1/1/2012"
              Else
                  txtDateReturned.Text = key(5)
              End If
      
              If IsDBNull(key(6)) Then
                  txtReturningDepartment.Text = ""
              Else
                  txtReturningDepartment.Text = key(6)
              End If
      
              If IsDBNull(key(7)) Then
                  txtReceivingOfficer.Text = ""
              Else
                  txtReceivingOfficer.Text = key(7)
              End If
      
              If IsDBNull(key(8)) Then
                  txtRemarks.Text = ""
              Else
                  txtRemarks.Text = key(8)
              End If
      
      
          End Sub
      End Class


      sorry for taking so long to respond. this is the code for the find/search button and below is the code for the update button




      Code:
      Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUpdate.Click
      
              Dim UPDATE_FileTransacUpdate As New Records_Mgmt_BLL.FileTransac
              Dim _GET_FileTransacUpdate As New FileTransacUpdate
      
              Dim Department_ID As String = txtDepartmentID.Text
              Dim Sequence_ID As String = txtSequenceID.Text
              Dim Requesting_Officer As String = txtRequestingOfficer.Text
              Dim Date_Requested As String = txtDateRequested.Text
              Dim Date_Sent As String = txtDateSent.Text
              Dim Date_Returned As String = txtDateReturned.Text
              Dim Returning_Department As String = txtReturningDepartment.Text
              Dim Receiving_Officer As String = txtReceivingOfficer.Text
              Dim Remarks As String = txtRemarks.Text
      
              Try
      
                  UPDATE_FileTransacUpdate.UpdateFileTransacUpdate(Department_ID, Sequence_ID, Date_Requested, Returning_Department, Receiving_Officer, Remarks)
                  cmdUpdate.Visible = False
                  Dim str As String = "<script>window.open('FileTransacUpdate.aspx?" & Department_ID & "','','height=320,width=1200')</script>"
                  Page.ClientScript.RegisterStartupScript(Me.GetType(), "print_script", str)
              Catch ex As Exception
      
                  MsgBox(ex.ToString)
      
              End Try
      
          End Sub

      Please assist.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Just from the error code, it sounds like you're trying to insert a blank string into a date field. A blank string can't be converted to a date. It is not caught by your null check because a blank string is not a null.

        Comment

        • abby1
          New Member
          • Feb 2012
          • 12

          #5
          But the insert form is actually working. this is the coding for the find and update button and i am getting that error which have me very confused.

          Comment

          Working...