Sébastien
Sébastien

Reputation: 79

Datatable Select with Datetime

In the second For Each, I want to select all records with EmailCreateDate = dtEmailCreateDate, but no record is found. Does someone have an idea ?

Dim dtEmailCreateDate As DateTime = Date.Now    
For Each row In _tblMandantenData.Select("Selected = True AND EmailSentDate IS NULL")
    row("EmailCreateDate") = dtEmailCreateDate
    DBAccess.UpdateEmailVersandInfos(row)
Next

Dim strQuery = String.Format("Selected = True AND EmailCreateDate = '{0}'", dtEmailCreateDate.ToString())    
For Each rowToSent In _tblMandantenData.Select(strQuery)  
    SentMail(rowToSent)
Next

Upvotes: 1

Views: 7037

Answers (2)

Steve
Steve

Reputation: 216293

If you look at the Expression property of the DataColumn (the rules outlined there are the rules to use for the Select filter expression) you will notice that a filter on DateTime column is created enclosing the date between the number symbol (#)

 DateTimeColumn = #value#

Moreover the date should be formatted according to the format MM-dd-yyyy and thus your code should check the dates with this expression

Dim strQuery = String.Format("Selected = True AND " & _ 
               "EmailCreateDate = #{0}#", dtEmailCreateDate.ToString("MM-dd-yyyy"))    

Of course this could still fail if the column named EmailCreateDate contains also information about times and thus you should change your formatting to include also output for time "HH:mm:ss" or better use a BETWEEN syntax

Upvotes: 4

UVData
UVData

Reputation: 511

My guess - check if values are really present in DB. If yes, Check if values passed is really matching to values stored in DB. Even if there is a difference in milliseconds you will not get data.

Upvotes: 0

Related Questions