Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Aug 2008
Posts: 5
#1: Aug 25 '08
Hi,
I'm using the following method to find the itemcode in a table.

Expand|Select|Wrap|Line Numbers
  1. dim ds as new dataset
  2. dim mvItem as object
  3.  
  4. Dim tmpCol(1) As DataColumn
  5. tmpCol(0) = dsPDT.Tables(0).Columns(0)
  6. dsPDT.Tables(0).PrimaryKey = tmpCol
  7.  
  8. mvItem = dsBoss.Tables(0).Rows(i)(0).ToString
  9. If dsPDT.Tables(0).Rows.Contains(mvItem) = False Then
  10.      do something
  11. else
  12.      do something
  13. endif
  14.  
  15. ITEM_CODE                                 NOT NULL VARCHAR2(13)
  16. ITEM_SCAN_CODE                                     VARCHAR2(20)
  17. 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 ?

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Aug 25 '08

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


.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?
Newbie
 
Join Date: Aug 2008
Posts: 5
#3: Aug 26 '08

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


Quote:

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.
Expand|Select|Wrap|Line Numbers
  1.  mvItem = dsBoss.Tables(0).Rows(i)(0).ToString 
ITEM_CODE I've declared as string but it contains numeric value only(i.e. 100045020 )
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Aug 26 '08

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


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?
Reply