Link to home
Start Free TrialLog in
Avatar of whittlephilip
whittlephilip

asked on

boolean field check

How to check if field in access database is set to true or false through code? For example, I would like to do something like ..

if field = true then
... perform some action
end if
Avatar of amyhxu
amyhxu

Have you got records from Access through dataadapter or DataReader ?
if you use dataadapter to fill dataset:
  Dim dRow as DataRow = mydataset.Tables("mydatatable").Rows(rowIndex)
  If Not IsDbNull(dRow(BoolCol")) AndAlso dRow("BoolCol") Then  'same effect as "If Not IsDbNull(dRow(BoolCol")) AndAlso dRow("BoolCol") = True Then "
      ...
  End If

If you use DataReader:
  Dim dr as DataReader
  'execute datareader
  If NOT dr IS Nothing Then
     If dr("BoolCol") Then    'Same as "If dr("BoolCol") = True Then"
      ....
     End If
Avatar of whittlephilip

ASKER

Hi amyhxu

I appreciate your attempt to help me. At run time I kept getting the error message saying there was no row at position 0.

At this point I really don't care ;-) This was so much easier in VB6, and can't understand why its become so complex. I guess I'll stick with vb6.
ASKER CERTIFIED SOLUTION
Avatar of amyhxu
amyhxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi amyhxu

Good tip. If I may elaborate, I am making headway, thanks to your tip. But I do have one more piece to this question. In the dRow declaration

-- Dim dRow as DataRow = mydataset.Tables("mydatatable").Rows(rowIndex) --

Each rowIndex is called randomly by another function. How should I approach the rowIndex if it is random instead of fixed?

Thanks for you support.

Philip
Hi ... I think I fixed my problem with random row selection.