I have a sub that on a button click is supposed to query my SQL database pull all the results that match ant then weed out the ones that don't fit user defined values.
dt1 and dt2 are datePickers for the start and end date. the date is stored as a string in the database and parsed on retrieval. I know there is something weird with For each loop and DELETE because of index numbers, but all the work around I have tries the IF THEN statement does not run.
Private Sub getdata_Click(sender As Object, e As RoutedEventArgs) Handles getdata.Click
Dim dt As New DataTable
dt.Dispose()
SQL.AddParam("@name", emplistadm.Text.ToString)
SQL.ExecQuery("SELECT EmployeeName, PunchIn, PunchOut, HoursWorked FROM PUNCHES WHERE EmployeeName = @name And CurrentStatus = 0 AND Processed = 0")
Dim dt1 As DateTime = startdate.DisplayDate
Dim dt2 As DateTime = enddate.DisplayDate
Dim dt1int As Int16 = DatePart(DateInterval.DayOfYear, dt1)
Dim dt2int As Int16 = DatePart(DateInterval.DayOfYear, dt2)
For Each dr As DataRow In dt.Rows
Dim dt3 As DateTime = DateTime.Parse(dr("PunchIn"))
Dim dt3int As Int16 = DatePart(DateInterval.DayOfYear, dt3)
If dt3int > dt2int AndAlso dt3int < dt1int Then
dr.Delete()
End If
Next
dt = SQL.SQLDS.Tables(0)
dataGrid.ItemsSource = dt.DefaultView
End Sub
I know I need to call the accept changes also but when I replace the dr.delete with msgbox("dakjhfdsalkjf") It still doesn't show the message box.
Option Strict Onat the top of the source code file. Now the compiler tells you what you did wrong.If dt3.Date > dt2.Date AndAlso dt3.Date < dt1.Date Then...If dt3int > dt2int AndAlso dt3int < dt1int Thenseems to readif punchin > end date to display and punchin < begin date to displayso it has to be after and before the display window at the same time?