Hi, I'm just confuse about this.. I am making a form with 2 datetimepicker controls which are the Start and End date and when I click the action button it displays all the departments covered with the start-end date and it works fine but the problem is it loads all departments even if there are equal values like this image Click Here What I want is if there are 3 rows with same values it should be 1 row only but I don't have any idea on coding that.

Here's my code:


            Using conn As New OleDbConnection("Provider = Microsoft.Jet.Oledb.4.0; Data source =" & MyConString & ";Jet OLEDB:Database Password=mydbdatapass;")
                Dim DateStart As String = ConversionHelper1.ConvertDateToYMD(DStart.Value)
                Dim DateEnd As String = ConversionHelper1.ConvertDateToYMD(DEnd.Value)

                Dim command As New OleDbCommand("Select Dept From SoldItems Where SalesDate >= @StartDate And SalesDate <= @EndDate", conn)
                With command.Parameters
                    .AddWithValue("@StartDate", DateStart)
                    .AddWithValue("@EndDate", DateEnd)
                End With
                Dim da As New OleDbDataAdapter
                Dim dt As New DataTable
                da.SelectCommand = command
                DataGridView1.DataSource = dt
            End Using

        Catch ex As Exception
        End Try


Try modifying the SQL statement from Select Dept From SoldItems Where SalesDate >= @StartDate And SalesDate <= @EndDate to Select Distinct Dept From SoldItems Where SalesDate >= @StartDate And SalesDate <= @EndDate

The DISTINCT command does precisely that i.e. returns only DISTINCT results.

Thanx a lot bro :) Problem solved.