Hi,
I am using vb.net and Access database.
In Access database there is a table named TblInvoiceQuery. It has DateofSale, InvoiceID, CustomerName, TypeofSale, SumOfTotal columns.
The DateofSale is set to general date format.
I have four datepickers named as - Datefrom, TimeFrom and DateTo, TimeTo.
Datagridview is used to display result. The Datagridview is unbounded for datasource because TblInvoiceQuery is a query based table.
A button named Showdata is used for code.
The code is -
I have a combo box named as CmbCustomername which has Customer names in it.
I want to search by date range and by Customer name.
How should I write code for searching both ?
Thanks in advance.
I am using vb.net and Access database.
In Access database there is a table named TblInvoiceQuery. It has DateofSale, InvoiceID, CustomerName, TypeofSale, SumOfTotal columns.
The DateofSale is set to general date format.
I have four datepickers named as - Datefrom, TimeFrom and DateTo, TimeTo.
Datagridview is used to display result. The Datagridview is unbounded for datasource because TblInvoiceQuery is a query based table.
A button named Showdata is used for code.
The code is -
VB.NET:
Private Sub Showdata()
con.Close()
con.Open()
Dim cmd As New OleDbCommand("select * from [TblInvoiceQuery] where DateofSale between #" & DateFrom.Value.Date & " " & TimeFrom.Value.ToShortTimeString & "# And #" & DateTo.Value.Date & " " & TimeTo.Value.ToShortTimeString & "#", con)
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
da.SelectCommand = cmd
dt.Clear()
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.Columns(0).DataPropertyName = "DateofSale"
DataGridView1.Columns(1).DataPropertyName = "InvoiceID"
DataGridView1.Columns(2).DataPropertyName = "CustomerName"
DataGridView1.Columns(3).DataPropertyName = "TypeofSale"
DataGridView1.Columns(4).DataPropertyName = "SumOfTotal"
DataGridView1.DataSource = dt
con.Close()
I have a combo box named as CmbCustomername which has Customer names in it.
I want to search by date range and by Customer name.
How should I write code for searching both ?
Thanks in advance.