Dim connection As OleDbConnection
        connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
       & "Data Source=" & Server.MapPath("~/Database/dbLupon.mdb") & ";")
        
        Dim command As OleDbCommand
        Dim commandPos As OleDbCommand
        
        commandPos = New OleDbCommand("Select POSITION_C FROM tblLupon_C WHERE POSITION = 'C' REGION_C = '" & lblRegion_C.Text & "' AND PROVINCE_C = '" & lblProvince_C.Text & "' AND CITYMUN_C = '" & cmbCityMun.SelectedValue & "' AND BARANGAY_C = '" & cmbBarangay.SelectedValue & "'")
        connection.Open()
        Dim DataReader As OleDbDataReader
        DataReader = commandPos.ExecuteReader()
        If GridView1.Rows.Count = 0 Then
            MsgBox("AKO!")
        Else
            While DataReader.Read
                MsgBox("duPLICATE")
            End While
        End If

Hi guys, I'm having a problem regarding duplicate data in the gridview.. I need one chairman on the record. thanks! :D

Recommended Answers

All 3 Replies

Use DISTINCT clause.

str="Select DISTINCT POSITION_C FROM tblLupon_C WHERE ...."

sir, the return error was

Executereader: COnnection property has not been initialized..

I used the code to validate that if there is a Chairman position in the data, it will not be accepted because it should have one chairman per barangay.

thanks sir :D

Command's Connection property is not set.

commandPos = New OleDbCommand("Select DISTINCT POSITION_C FROM tblLupon_C WHERE POSITION = 'C' REGION_C = '" & lblRegion_C.Text & "' AND PROVINCE_C = '" & lblProvince_C.Text & "' AND CITYMUN_C = '" & cmbCityMun.SelectedValue & "' AND BARANGAY_C = '" & cmbBarangay.SelectedValue & "'")
[I]commandPos.Connection=connection[/I]

connection.Open()
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.