But i am not getting the selected data displayed on the datagridview... pl do help me..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim dfrom As DateTime = DateTimePicker2.Value
        Dim dto As DateTime = DateTimePicker1.Value



        Dim SQLString As String = "SELECT * FROM cc WHERE Produced Between '" & DateTimePicker2.Value.Date & "' AND '" & DateTimePicker1.Value.Date & "'"

        Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
        Dim DataSet1 As New DataSet()
        Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)
        OleDBConn1.Open()
        OleDbDataAdapter1.Fill(DataSet1, "cc")
        DataGridView1.DataSource = DataSet1.Tables("cc")

        Dim total As Integer
        For Each row As DataGridViewRow In DataGridView1.Rows
            total += row.Cells("Total").Value
        Next
        TextBox2.Text = total

        Dim trejects As Integer
        For Each row As DataGridViewRow In DataGridView1.Rows
            trejects += row.Cells("TRejects").Value
        Next
        TextBox1.Text = trejects


    End Sub

What you've done seems to be correct. Try to take the SQL query to the server and run it there may be you have problems with the date format??

hi there sometime back i was working on an app that required the same command you want. searching data between two dates and the code i used really worked though takes some time to load the requested data when the dates are far apart.

try using shortdate format in your db and in your datetimepicker

Tried changing the short format..even then getting the same error in the 9th line near "cc" stating "datatype mismatch in crieteria expression." Struggling vth dis for two days...do help me....

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.