Results 1 to 3 of 3

Thread: Does Row Exist ???

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Does Row Exist ???

    Hi Peeps,

    I have several import routines that imports data from xml files. I currently use this code to see if the row already exists:-

    Code:
                    iRowExists = False
                    iCurrentRow = -1
                    For iRowCount = 0 To sqlDSStoreContacts.Tables(0).Rows.Count - 1
                        If sqlDSXMLStoreContacts.Tables(0).Rows(iRows).Item("SC_ST_STORECODE") = sqlDSStoreContacts.Tables(0).Rows(iRowCount).Item("SC_ST_STORECODE") And _
                           sqlDSXMLStoreContacts.Tables(0).Rows(iRows).Item("SC_NAME") = sqlDSStoreContacts.Tables(0).Rows(iRowCount).Item("SC_NAME") Then
                            iRowExists = True
                            iCurrentRow = iRowCount
                            Exit For
                        End If
                    Next
    My problem is that as the table grows the update takes forever. Is there a simpler way of determining if the rows exists you the unique columns as its identifier.

    Thanks for any assistance,

    Jiggy!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Does Row Exist ???

    You might try making a DataView from the DataTable, then using the RowFilter property to narrow your search considerably. I don't think you can filter on more than one column, so you would still be left with a loop looking for one of the two matches.

    You might also look at the DataTable.Merge function to see whether any of the various behaviors of that method would get the job done in a single step for you. It would mean creating a datatable (you already have one, it looks like) for the existing table, then making a datatable for the XML and merging the two. The behavior regarding conflicts might not be adequate for you, though.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,806

    Re: Does Row Exist ???

    Hi Mate,

    Thanks for that, in the end I used SQL statement and checked row count. This seemed to speed it up imensely.

    Thanks again,

    Jiggy!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width