Reputation: 1789
How can I write a loop to run for each day in the current month and then check to see if the Dataset has a record that matches one of those days and take an action?
For Day As Integer = 1 To DaysInTheMonth
For Each row In MyRows
If row.Date.Day = Day Then
' Yup! Found Data for this day!
' Add Data to string
Else
' No Data To Display
' Add Blank Field String
End If
Next
Next
This generates too many rows in the table I have it building. Basically, every day gets as many rows as there are that contain data.
I'm building a HTML table that gets mapped into a chart using jquery so I need a for everyday of the month.
Upvotes: 0
Views: 1059
Reputation: 38230
I think what would more suit your run would be having a day counter in the loop for the rows, so that you don't actually run over all the days again for each record in the datatable.
So now if you have the record its added to the string else skipped and the dat is incremented, so going down further you should get the required datapoints. give it a try
For Each row In MyRows
If row.Date.Day = Day Then
' Yup! Found Data for this day!
' Add Data to string
Else
' No Data To Display
' Add Blank Field String
End If
Day = Day + 1;
Next
Upvotes: 1
Reputation: 816
You should drop the first For loop as that's causing all rows to be selected. Instead set Day = Today. Ie
Day as Integer = date.day
Upvotes: 1