Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
VB
Dim connection As OleDbConnection
 connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
& "Data Source=" & Server.MapPath("~/Database/dbLupon.mdb") & ";")
 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


hello guys!
I'm having a problem regarding duplicate data.
Is my code right? I must have one Chairman in my record. thanks!
Posted
Comments
Albin Abel 20-Feb-11 22:18pm    
This code not seems to be having problem. Duplicates may be from the database itself?. If the table joins with other table (one to many) then in the result the parent column will have duplicates.
Henry Minute 20-Feb-11 22:22pm    
I cannot see anywhere in your code that you are putting any data into your GridView1. So I would expect that GridView1.Rows.Count will always be 0.
sevengenn 20-Feb-11 22:42pm    
I used those code to validate if there are existing chairman in the field position. but I can't run it correctly..

thanks for commets :)

Since you are using a query, it would be better to trace duplicate data in the query itself.
Dont allow duplicate data to be displayed in the gridview.
 
Share this answer
 
I don't see anywhere you are binding the result to the GridView1.

From the above code, I did few modification. I hope this would help to find the duplicates.

VB
If Not DataReader.HasRows Then
    MsgBox("AKO!")
Else
    While DataReader.Read
        MsgBox("duPLICATE")
    End While
End If



Mark it as answer if it is helpful.
 
Share this answer
 
Comments
sevengenn 21-Feb-11 0:11am    
thanks for the help :)

it works! :) thank much! :)
Venkatesh Mookkan 21-Feb-11 0:29am    
You are most welcome.
sevengenn 21-Feb-11 0:42am    
sir, can I asked again some questions regarding this? in this thread?
Venkatesh Mookkan 21-Feb-11 0:45am    
You will get more responses (from others too), if you start a new thread for other question. Moreover, I visit CP very less time.

So post is as new question.
sevengenn 21-Feb-11 0:48am    
thanks sir :)

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