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
Re: How to search Data by textbox and date in VB.net 80 80

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"
Re: How to search Data by textbox and date in VB.net 80 80

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

Re: How to search Data by textbox and date in VB.net 80 80

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.

Re: How to search Data by textbox and date in VB.net 80 80

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

Re: How to search Data by textbox and date in VB.net 80 80

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

Re: How to search Data by textbox and date in VB.net 80 80

Please start a new thread for this question.

Re: How to search Data by textbox and date in VB.net 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.