Hi Supergluey,
According to your code, Im not sure how do you want to filter the transactions by date and time. Do you want to first read the excel datatable and then filter it by your rule and finally add the result to the ListBox? If true, I think you could refer to the following demo. In the demo, first storing all CSV data to datatable and then filter it by date and time. This just provides you a method to achieve it, you could make some changes on it according to your needs.
Protected Sub btnOpenFile_Click(sender As Object, e As System.EventArgs) ' Check file select & valid file extension If Me.asyncfileupload1.HasFile Then Try Dim arrFileName As [String]() = Me.asyncfileupload1.FileName.Split("."C) Dim filename As String = System.IO.Path.GetFileName(asyncfileupload1.PostedFile.FileName) Dim strTimestamp As String = DateTime.Now.ToString("yyyyMMddHHmmssfff") Dim currentPath As String = Server.MapPath("~/UploadsTemp/") + Path.GetFileName((Convert.ToString(arrFileName(0) + "_") & strTimestamp) + "." + arrFileName(1)) Dim dt As New DataTable("TranTable") dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Reader HOSTKEY", GetType([String])), New DataColumn("DATE", GetType(DateTime)), New DataColumn("CardID", GetType([String]))}) Dim dr As DataRow = Nothing Dim reader As StreamReader = Nothing Dim line As [String] = Nothing Dim arrCol As [String]() = Nothing 'asyncfileupload1.SaveAs(Server.MapPath("~/UploadsTemp/") + filename); Me.asyncfileupload1.SaveAs(currentPath) Try reader = New StreamReader(File.OpenRead(currentPath)) reader.ReadLine() ' Clear multi select box lbTrans.Items.Clear() While Not reader.EndOfStream line = reader.ReadLine() arrCol = line.Split(","C) dr = dt.NewRow() dr("Reader HOSTKEY") = arrCol(0) dr("DATE") = arrCol(1) dr("CardID") = arrCol(2) dt.Rows.Add(dr) End While ' All log or date range is matched If Not rdBtnLogDateAll.Checked Then Dim dtBegin As DateTime = Convert.ToDateTime("2015-08-01") 'here, you could get the value from front page Dim dtEnd As DateTime = Convert.ToDateTime("2015-08-31") 'here, you could get the value from front page 'get partial data Dim query = From record In dt.AsEnumerable() Where record.Field(Of DateTime)("DATE") > dtBegin AndAlso record.Field(Of DateTime)("DATE") < dtEndNew With { _ Key .[date] = record.Field(Of DateTime)("DATE"), _ Key .CardID = record.Field(Of String)("CardID") _ } ' Add to multi select box 'selTransaction.Items.Add(New ListItem(transactionDate + ", " + arrCol(1))) For Each item As var In query lbTrans.Items.Add(New ListItem(item.date + "," + item.CardID)) Next Else 'get all data Dim query = From record In dt.AsEnumerable()New With { _ Key .[date] = record.Field(Of DateTime)("DATE"), _ Key .CardID = record.Field(Of String)("CardID") _ } ' Add to multi select box 'selTransaction.Items.Add(New ListItem(transactionDate + ", " + arrCol(1))) For Each item As var In query lbTrans.Items.Add(New ListItem(item.date + "," + item.CardID)) Next End If ' Keep filename Session("PCRFileName") = Me.asyncfileupload1.PostedFile.FileName Catch ex As Exception Throw ex Finally reader.Close() dt = Nothing dr = Nothing reader = Nothing line = Nothing arrCol = Nothing strTimestamp = Nothing currentPath = Nothing End Try Catch ex As Exception Throw ex Finally End Try End If End Sub
For more things, you could refer to the following link. It provides the explanation about how to query a datatable using Linq.
I hope its useful to you.
Best Regards,
Weibo Zhang