Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
Checking for duplicate rows before adding a new row.
posted

I am working with a UltraWinGrid which has an attached UltraDataSource. Im using vb.NET to develop my application. My problem is that I cannot find an easy way to check if a row exists within the rows collection of either the WinGrid or the DataSource.

To add a new row to the datasource im using the following code:-

Dim o = New Object()  {False, emailImage, status}
dsDocuments.Rows.Add(o)

This will add the row to the datasource and the wingrid fine, however some of the rows which I will add contain duplicate data and I need a way to detect if the data already exists so I can cancel the row being added. I have tried using the following to no avail:-

If  Not (dsDocuments.Rows.Contains(o)) Then
      dsDocuments.Rows.Add(o)
End If

However the compiler shows an error as the array cannot be converted to an gridrow or a datasourcerow. I have tried using the events raised (rowadding & rowadded) and still cannot find a solution.

Is there an easy way to check if a duplicate row exists without looping through each row?

 

Thanks

Sean 

Parents
No Data
Reply
  • 280
    posted

    hi 53an  I M VB.NET DEVELOPER in my project i check and prevent to add duplicate row in this way PLEASE CHANGE ACCORDING YOUR REQUIRMENT

    Dim frmdrug As New frmDrugSearch

    Dim rw As UltraGridRow = Cbxprovider.SelectedRow()

    If frmdrug.ShowDialog(ListFormOpenMode.SelectionOnly) = Windows.Forms.DialogResult.OK Then
    If dsView.Tables(0).Select("DRUG_NDC = '" + frmdrug.DRUG_NDC + "' AND PROVIDER_ID = " + selectedProvider + " ").Length = 0 Then
    Dim newRow As DataRow = dsView.Tables(0).NewRow
    newRow("DRUG_ID") = frmdrug.MEDICATION_ID
    newRow("DRUG_NDC") = frmdrug.DRUG_NDC
    newRow("DRUG_NAME") = frmdrug.BRAND_NAME
    newRow("ACTIVE") = True
    newRow("PROVIDER_ID") = selectedProvider
    dsView.Tables(0).Rows.Add(newRow)
    Else
    MessageBox.Show("Selected DRUG Already Exists", "Add")
    End If

    IF U NEED MORE HELP PLEASE CONTACT ME AT BELOW LINK

    http://ahmadkhalid44.blogspot.com/

    Regards:

    Ahmad Khalid

    Software Engineer

Children
No Data