0

Hi
How can i check if some value exists in the data reader
How can i do that ? any ideas please .

3
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by Oxiegen
Featured Replies
  • [CODE] IF dataReader.Read() Then If Not IsDBNull(dataReader("dateColumn")) Then Dim dateTest As DateTime ' Test to see if the value in the database is a date If DateTime.TryParse(dataReader("dateColumn"), dateTest) Then If dateTest = DateTime.Now Then ' Do something End If End If END IF End If [/CODE] Read More

  • That is true. However, before you can safely check the value, you need to check if the value exist. Errors have been known to occur from time to time when [B]storing[/B] to a database. Therefore, first check if value exists. Then check if the value happens to be NULL. After … Read More

0

>How can i check if some value exists in the data reader
How can i do that ?

IF dataReader.Read() Then
    IF IsDBNull(dataReader("col1")) Then
    ...
    ELSE
    ....
    END IF
End If
0

Thank you, But i don't mean that
I have a dates in the DR column1
And i want to check if :

If DateTime.Now = 'Any value in the column1
1
IF dataReader.Read() Then
    If Not IsDBNull(dataReader("dateColumn")) Then
        Dim dateTest As DateTime
        ' Test to see if the value in the database is a date
        If DateTime.TryParse(dataReader("dateColumn"), dateTest) Then
            If dateTest = DateTime.Now Then
                ' Do something
            End If
        End If
    END IF
End If
0

It does not work :'(
The column1 in datareader is a datetime in the DB
So maybe i don't need to check if its date or not.

Edited by bninja: n/a

0

Read post #2 and #4 - dataReader.Read() method returns true if value exists, return false otherwise.

0

I am not checking if value exist
I want to check about a certain value (DateTime.Now)
dr.read only check if any value exist

1

That is true.
However, before you can safely check the value, you need to check if the value exist.
Errors have been known to occur from time to time when storing to a database.
Therefore, first check if value exists. Then check if the value happens to be NULL.
After that, you can do your thing.

This is the part you're asking for.
In order to compare two dates, first make sure they are of the same type. Hence the call to DateTime.TryParse() method.

Dim dateTest As DateTime
        ' Test to see if the value in the database is a date
        If DateTime.TryParse(dataReader("dateColumn"), dateTest) Then
            If dateTest = DateTime.Now Then
                ' Do something
            End If
        End If
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.