B
Barry
Hi All
I am trying to search a DataSet by Year and return all the records in the
DataSet for that year.I've tried loops and keep getting an exception error
when I Just use a year for my search. Here's my basic coding which works
for finding a particular date and adds it to the list.
Thanks Barry
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
'Clears listbox for next Search
lstDisplay.Items.Clear()
'Declarations
Dim i As Integer
Dim RowIndex1 As Integer
'Creates new DataTable and Fills It, and adds column headings
Dim fmtStr As String = "{0,-40}{1,-40}{2,25:N1}{3,25:N1}{4,25:N1}{5,35}"
Dim dt As New DataTable
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =
Milage.MDB"
Dim sqlStr As String = "SELECT * FROM Miles"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
lstDisplay.Items.Add(String.Format(fmtStr, "Purpose Of Trip", "Who I
Visited", "Starting Milage", "Ending Milage", "Miles This Trip", "Date"))
Dim Date1 As Date
Dim Date1Found As Boolean = False
Date1 = InputBox("Enter Start Date For Report")
For i = 0 To (dt.Rows.Count - 1)
If CStr(dt.Rows(i)("Date")) = Date1 Then
Date1Found = True
RowIndex1 = i
lstDisplay.Items.Add(String.Format(fmtStr, dt.Rows(i)(0), dt.Rows(i)(1),
dt.Rows(i)(2), dt.Rows(i)(3), _
dt.Rows(i)(4), dt.Rows(i)(5)))
End If
Next
If (Not Date1Found) Then
MsgBox("Cannot find the records requested!")
End If
End Sub
I am trying to search a DataSet by Year and return all the records in the
DataSet for that year.I've tried loops and keep getting an exception error
when I Just use a year for my search. Here's my basic coding which works
for finding a particular date and adds it to the list.
Thanks Barry
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click
'Clears listbox for next Search
lstDisplay.Items.Clear()
'Declarations
Dim i As Integer
Dim RowIndex1 As Integer
'Creates new DataTable and Fills It, and adds column headings
Dim fmtStr As String = "{0,-40}{1,-40}{2,25:N1}{3,25:N1}{4,25:N1}{5,35}"
Dim dt As New DataTable
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =
Milage.MDB"
Dim sqlStr As String = "SELECT * FROM Miles"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
lstDisplay.Items.Add(String.Format(fmtStr, "Purpose Of Trip", "Who I
Visited", "Starting Milage", "Ending Milage", "Miles This Trip", "Date"))
Dim Date1 As Date
Dim Date1Found As Boolean = False
Date1 = InputBox("Enter Start Date For Report")
For i = 0 To (dt.Rows.Count - 1)
If CStr(dt.Rows(i)("Date")) = Date1 Then
Date1Found = True
RowIndex1 = i
lstDisplay.Items.Add(String.Format(fmtStr, dt.Rows(i)(0), dt.Rows(i)(1),
dt.Rows(i)(2), dt.Rows(i)(3), _
dt.Rows(i)(4), dt.Rows(i)(5)))
End If
Next
If (Not Date1Found) Then
MsgBox("Cannot find the records requested!")
End If
End Sub