• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

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

0
itnifl
Asked:
itnifl
1 Solution
 
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
 
peakpeakCommented:
You can also use the actual values: 0 for false and 1 for true.
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
Gustav BrockCIOCommented:
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
 
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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now