Rows.contains sometimes return false even though the value is there

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abutaher
    New Member
    • Aug 2008
    • 5

    Rows.contains sometimes return false even though the value is there

    Hi,
    I'm using the following method to find the itemcode in a table.

    Code:
    dim ds as new dataset
    dim mvItem as object
    
    Dim tmpCol(1) As DataColumn
    tmpCol(0) = dsPDT.Tables(0).Columns(0)
    dsPDT.Tables(0).PrimaryKey = tmpCol
    
    mvItem = dsBoss.Tables(0).Rows(i)(0).ToString
    If dsPDT.Tables(0).Rows.Contains(mvItem) = False Then
         do something
    else
         do something
    endif
    
    ITEM_CODE                                 NOT NULL VARCHAR2(13)
    ITEM_SCAN_CODE                                     VARCHAR2(20)
    ITEM_SUPL_CODE                                     VARCHAR2(5)
    Here ITEM_CODE is the primary key and ITEM_CODE contains 9 digits and 13 digit.

    Sometime the contains retunring false even though the Item is ther in the dataset.

    Could anyone help me please to solve this issue ?
    Last edited by kenobewan; Aug 25 '08, 12:52 PM. Reason: Please use code tags
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    .contains comapres objects types, not just a human readable value.
    If your string value is "3456" because the column it looked at was an integer column with that value, doing a .contains on an integer column with a string representation will fail.
    You have declared mvItem as an object, but are always assigning it to be a string with that ToString call, I think getting rid of that will help solve your problem?

    Comment

    • abutaher
      New Member
      • Aug 2008
      • 5

      #3
      Originally posted by Plater
      .contains comapres objects types, not just a human readable value.
      If your string value is "3456" because the column it looked at was an integer column with that value, doing a .contains on an integer column with a string representation will fail.
      You have declared mvItem as an object, but are always assigning it to be a string with that ToString call, I think getting rid of that will help solve your problem?
      Dear,
      I've removed ToString from the following line but still it is returning false.
      Code:
       mvItem = dsBoss.Tables(0).Rows(i)(0).ToString
      ITEM_CODE I've declared as string but it contains numeric value only(i.e. 100045020 )

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Does it EVER return true? Its looking for the primary key which you just declared which column was the primary key?

        Have you tried setting a break point and stepping through the code, to see what it is being compared to?

        Comment

        Working...