VB .Net - Boolean Values in Access database

How do I handle boolean values in a access database? I want ionvert the value of what exists in the database. If the value is false in the cell, I want to make it true. And the other way around. I was thinking something like below:
Dim assetRow As dataset.assetRow
assetRow = Dataset.assetRow.FindByassetnr(assetNr)
If IsDBNull(assetRow.active) Then
                    With assetRow
                        .BeginEdit()
                        .active = true
                        .EndEdit()
                    End With
                End If
                If assetRow.active = True Then
                    With assetRow
                        .BeginEdit()
                        .active = false
                        .EndEdit()
                    End With
                Else
                    With assetRow
                        .BeginEdit()
                        .active = true
                        .EndEdit()
                    End With
                End If
            End If
Dataadapter.Update(Dataset.GetChanges())

Open in new window

LVL 2
itniflAsked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
I would do it like this.

/gustav
Dim assetRow As dataset.assetRow
assetRow = Dataset.assetRow.FindByassetnr(assetNr)
With assetRow
  .BeginEdit()
    If IsDBNull(.active) Then
      .active = true
    Else
      .active = Not .active
    End If
  .EndEdit()
End With
Dataadapter.Update(Dataset.GetChanges())

Open in new window

0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Have you tried:

.active = Not .active

0
 
itniflAuthor Commented:
No, not yet, but shouldnt it be ok to use false and true?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
peakpeakCommented:
You can also use the actual values: 0 for false and 1 for true.
0
 
itniflAuthor Commented:
Yeah the allignment of the values are ok, but the problem now is that the changes dont get stored to the database. The are updated in the grid, but they are never stored to the database. I thought Dataadapter.Update(Dataset.GetChanges()) followed by Dataset.AcceptChanges() would do that. Any ideas?
0
 
Anthony PerkinsCommented:
>>No, not yet, but shouldnt it be ok to use false and true?<<
Yes.

>>You can also use the actual values: 0 for false and 1 for true.<<
I suspect you mean 0 and -1
0
 
itniflAuthor Commented:
I never actually fixed the error where the values didnt get stored in the database, but they did get inverted in the dataset and datagrid.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.