0

Hi..all
I'm newbie in VB.net
Please Help me..
How to search data by textbox and datetimepicker access 2003 database in VB.net

Exp : I want to search for data based on the Part name and two datetimepicker

I try with code like this but the results are not in line with expectations

Private Sub SearchData()
con.Open()
        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter
        'da = New OleDbDataAdapter(com)
        If cbaktif.Checked = True Then
            da = New OleDbDataAdapter("Select * from AFINITY where Description = '" & TextBox1.Text & "' and " & " Datetgl between #" & DateTimePicker1.Text & "# and #" & DateTimePicker2.Text & "# ", con)
        Else
            da = New OleDbDataAdapter("Select * from AFINITY where Description like '%" & TextBox1.Text & "%'", con)
        End If
        da.Fill(dt)
        DatagridView1.DataSource = dt.DefaultView
        con.Close()
End Sub
5
Contributors
7
Replies
32
Views
5 Years
Discussion Span
Last Post by jared.geli
0

I would go to use >= and <= operators to define the start end end date accordingly:

Dim query As String = "Select * from AFINITY where Description = @description and Datetgl >= @startDate and Datetgl <= endDate"
0

thank you for the response.. @Mitja
i try your code but nothing happen...whats wrong?...
maybe i don't know in using your code because i am very NewBie
Please can you explain or example in detail...

thanks very much

0

What are the data type in your Datetgl field (column)? Are an actualy DateTime (date) type?
Or some string? If so, this will not work. It must be an actualy type of DateTime.

0

ya...actualy data type in my table access (column) date type dd/mm/yyyy
i have one table AFINITY

0

What happens when you run your code? Try removing the ds.Tables.Add(dt) in your code.

Edit: Sorry for Necroing.

Edited by jared.geli

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.