Click here to Skip to main content
15,886,740 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am using access database. I tried to make query selecting a date from datetimepicker. But I didn't get any row. From combobox using the same query I got the desired row. Please help me.

My code is here:
Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim da, da1 As OleDb.OleDbDataAdapter
    Dim ds, ds1 As New DataSet
    Dim s As New connect.Class1
    Dim i, j As Integer

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = s.a1
        con.Open()
        da1 = New OleDb.OleDbDataAdapter("Select Dat from Sale", con)
        da1.Fill(ds1, "Tab")
        i = ds1.Tables("Tab").Rows.Count
        For j = 0 To i - 1
            ComboBox3.Items.Add(ds1.Tables("Tab").Rows(j).Item(0))
        Next

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If RadioButton1.Checked = True Then
            Dim cmb As String
            cmb = Trim(ComboBox3.Text)
            'cmb = DateTimePicker1.Text
            ds.Clear()
            'da = New OleDb.OleDbDataAdapter("Select * from Sale where Dat='" & cmb & "'", con)
            da = New OleDb.OleDbDataAdapter("Select * from Sale where Dat='" & cmb & "'", con)
            da.Fill(ds, "Tab")
            con.Close()
            DataGridView1.DataSource = ds.Tables("Tab").DefaultView
            DataGridView1.Show()
        End If
    End Sub
End Class





Namespace connect
    Public Class Class1
        Public a1 As String = "Provider=microsoft.jet.oledb.4.0;data source=D:\CDshop.mdb"
    End Class
End Namespace
Posted
Updated 8-Jun-11 16:49pm
v2
Comments
HimanshuJoshi 8-Jun-11 22:49pm    
Edited to add pre tags around code.

1 solution

Try setting the relevant date format
VB
cmb = DateTimePicker1.Value.ToString("yyyy-MM-dd") 'Replace the format(yyyy-MM-dd) with what you have in access database
 
Share this answer
 
Comments
Vinod Gautam 9-Jun-11 8:22am    
Thank you Amit ji. After doing this change I got the desired result. "Select * from Sale where Dat=#"& cmb & "#", con)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900