Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2010 [RESOLVED] Compare date in textbox with date in database problem

$
0
0
Hello,

I am trying to compare the date in my textbox with the date in my database.

I am using the following code but I still get the error when the textbox containes a date and the databasefield contains null:
"Conversion from type 'DBNull' to type 'Date' is not valid."


What am I doing wrong???



Code:

Public Function ThereAreChangesDatum(ByVal txtTextBox As System.Windows.Forms.TextBox, ByVal DataReader As SqlDataReader, ByVal DB_Veld As String, ByVal DB_Index As Integer) As Boolean
    If txtTextBox.Text <> String.Empty And DataReader.IsDBNull(DB_Index) OrElse
      (txtTextBox.Text <> String.Empty AndAlso CDate(txtTextBox.Text) <> CDate(DataReader(DB_Veld))) Then
      Return True
    ElseIf txtTextBox.Text = String.Empty And Not DataReader.IsDBNull(DB_Index) Then
      Return True
    Else
      Return False
    End If
  End Function


Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>