Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am trying to find a row in a dataset with a column value. The column is a boolean data type.
VB
 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
Updated 29-Aug-11 18:53pm
v2

If it is boolean, simply try this.
VB
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.
VB
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.
 
Share this answer
 
v3
Comments
jrameshan 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 30-Aug-11 1:50am    
Debug and find the bug. Your logic seems wrong to me. Updated the answer.
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900