# Visual Basic > Database Development >  [RESOLVED] How can I check a checkbox using a database record?

## The_Hobbyist

I want to pull a record from my database and either check or uncheck a checkbox, depending on that record.  I have 7 different checkboxes that I want this to happen with and each checkbox is tied to a unique field in the table.

- The database's *table* I'll be pulling from is "ScientificData"
- The *field*'s within the table are: Purple, Navy, Indigo, Green, Yellow, Orange and Red

Question: How do I take the below table data (there are other fields in the table but they are used upon elsewhere - not here so I have left them out of this illustration) and translate the YES records into a checkbox.checked=True and the NO records into a checkbox.check=false?  Should a record of ZEROs and ONEs be used for Yes/No records?  Is TEXT like YES or NO the way to go here?

It should be noted that EACH of the fields (Purple, Navy, Indigo, Green, Yellow, Orange and Red) are directly related to a single checkbox on the form.  That is to say that the form has 7 checkboxes.  They are as follow:

1. chkPurple
2. chkNavy
3. chkIndigo
4. chkGreen
5. chkYellow
6. chkOrange
7. chkRed

What should I be looking into or researching in an effort to better understand how to start this portion of my project?  Is there a name for this type of return?  I'm quite lost here...Obviously.

ScientificData
AutoID
Purple
Navy
Indigo
Green
Yellow
Orange
Red

1
YES
NO
NO
NO
YES
NO
NO

2
NO
NO
NO
NO
YES
YES
NO

3
YES
NO
NO
NO
NO
NO
YES



I don't know if any of my existing code is relevant or not. I suspect some of it is as it calls upon the table already.  I'll share a watered down version of what I currently have going on just incase:



```
Imports System.Data.SQLite

Public Class frmMain

    Private CON As New SQLiteConnection("Data Source= C:\FilePath\The_Database.db;Version=3")

    Private WithEvents ScienceAdapter As New SQLiteDataAdapter("SELECT AutoID, ItemName, HardnessA, HardnessB, DensityA, DensityB, Magnetic, Purple, Navy, Indigo, Green, Yellow, Orange, Red, ChemistryID FROM ScientificData", CON)
    Private WithEvents ChemistryAdapter As New SQLiteDataAdapter("SELECT AutoID, ChemicalFormula FROM ChemistryData", CON)

    Private ScienceDataTable As New DataTable
    Private ChemistryDataTable As New DataTable

    Private ScienceBindingSource As New BindingSource
    Private cmdBldrScience As New SQLiteCommandBuilder(ScienceAdapter)


    Private Sub frmMain_Load(Sender As Object, e As EventArgs) Handles Me.Load

        ScienceAdapter.Fill(ScienceDataTable)
        ChemistryAdapter.Fill(ChemistryDataTable)

        Me.cmbChemicalFormula.DisplayMember = "ChemicalFormula"
        Me.cmbChemicalFormula.ValueMember = "AutoID"
        Me.cmbChemicalFormula.SelectedValue = "AutoID"
        Me.cmbChemicalFormula.DataSource = ChemistryDataTable

        SetUpBindings()

    End Sub


    Private Sub SetUpBindings()

        ScienceBindingSource.DataSource = ScienceDataTable

        Me.txtName.DataBindings.Add("Text", ScienceBindingSource, "ItemName")
        Me.txtHardnessA.DataBindings.Add("Text", ScienceBindingSource, "HardnessA")
        Me.txtHardnessB.DataBindings.Add("Text", ScienceBindingSource, "HardnessB")
        Me.txtDensityA.DataBindings.Add("Text", ScienceBindingSource, "DensityA")
        Me.txtDensityB.DataBindings.Add("Text", ScienceBindingSource, "DensityB")
        Me.txtMagnetic.DataBindings.Add("Text", ScienceBindingSource, "Magnetic")
        Me.cmbChemicalFormula.DataBindings.Add("SelectedValue", ScienceBindingSource, "ChemistryID")


        Me.DataGridView1.DataSource = ScienceBindingSource

    End Sub
```

Thank you for any help/guidance you can provide.

----------


## jmcilhinney

You can create Bindings for the Checked properties of the CheckBoxes in basically the same way you are for everything else. You can then handle the Format and Parse events of those Bindings and convert between the Strings "YES" and "NO" and the Boolean values True and False. You would only need one handler for each event to handle all Bindings. I'm not sure but you may need to set FormattingEnabled to True on the Binding for those events to be raised.

----------


## The_Hobbyist

> You can create Bindings for the Checked properties of the CheckBoxes in basically the same way you are for everything else. You can then handle the Format and Parse events of those Bindings and convert between the Strings "YES" and "NO" and the Boolean values True and False. You would only need one handler for each event to handle all Bindings. I'm not sure but you may need to set FormattingEnabled to True on the Binding for those events to be raised.


Ok.... This gives me some direction and a better idea of what I need to look into.  Thank you!

----------


## The_Hobbyist

OK.  This worked for me.... I did "a thing"!  Thank you!

I changed the fields in the table to TYPE NUMERIC and used "0" for no and "1" for yes and then plopped in the code below:



```
    Private Sub SetUpBindings()

        ScienceBindingSource.DataSource = ScienceDataTable

        Me.chkPurple.DataBindings.Add("Checked", ScienceBindingSource, "Purple")
        Me.chkNavy.DataBindings.Add("Checked", ScienceBindingSource, "Navy")
        Me.chkIndigo.DataBindings.Add("Checked", ScienceBindingSource, "Indigo")
        Me.chkGreen.DataBindings.Add("Checked", ScienceBindingSource, "Green")
        Me.chkYellow.DataBindings.Add("Checked", ScienceBindingSource, "Yellow")
        Me.chkOrange.DataBindings.Add("Checked", ScienceBindingSource, "Orange")
        Me.chkRed.DataBindings.Add("Checked", ScienceBindingSource, "Red")

        Me.DataGridView1.DataSource = ScienceBindingSource

   End Sub
```

----------

