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

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"

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

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.

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

hii i wnat to search data from database by entering two fields in textbox

Please start a new thread for this question.

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

Edit: Sorry for Necroing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.