Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I am trying to find a row in a dataset with a column value. The column is a boolean data type.
 Dim foundRows() As Data.DataRow
foundRows = dsans.Tables(0).Select("correct_ans = 'true'")
               Dim j As Integer
               Dim iRowIndex As Integer
               For j = 0 To dtans.Rows.Count - 1
                   If dtans.Rows(j).Equals(foundRows) Then
                       iRowIndex = j
                       Exit For
                   End If
               Next
               answer = dtans.Rows(iRowIndex).Item(1)
Everytime it returns the first row.It is not checking the condition
correct_ans = 'true'. Is anything wrong in the select statement?
Posted 29-Aug-11 19:51pm
Edited 29-Aug-11 19:53pm
Prerak Patel140.6K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If it is boolean, simply try this.
dsans.Tables(0).Select("correct_ans") ' or "NOT correct_ans"
Your comparison is for string types, not for boolean.
[Edit]
I really missed this part when I found problem at first.
For j = 0 To dtans.Rows.Count - 1
  If dtans.Rows(j).Equals(foundRows) Then
    iRowIndex = j
    Exit For
  End If
Next
foundRows is array of DataRow. What you are trying to is to equate DataRow to it.
  Permalink  
v3
Comments
jrameshan at 30-Aug-11 1:10am
   
select("correct_ans")didn't work.It is again returning the first row. Not sure if I can use select("NOT correct_ans") because I have 3 rows which are false and only one row which is true.
Prerak Patel at 30-Aug-11 1:50am
   
Debug and find the bug. Your logic seems wrong to me. Updated the answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

What is the type of the correct_ans field. Is it boolean or string?
 
The comparison you are doing here is essentially a string so there are no results returned if the types are not matching.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,438
1 OriginalGriff 6,491
2 Peter Leow 3,567
3 Zoltán Zörgő 3,326
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 30 Aug 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100