By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

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

P: 5
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 ?
Aug 25 '08 #1
Share this Question
Share on Google+
3 Replies


Plater
Expert 5K+
P: 7,872
.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?
Aug 25 '08 #2

P: 5
.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 )
Aug 26 '08 #3

Plater
Expert 5K+
P: 7,872
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?
Aug 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.