How to Databind a CheckBoxAdv to Integer Field in SQL Database

7 Jan 20223 minutes to read

The CheckBoxAdv IntValue property can be used to data bind to integer values as illustrated below.

public partial class Form1 : Form
    public static string dataBasePath = Path.GetFullPath("..\\..\\Database1.mdf");
    public  string connectString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + dataBasePath + ";Integrated Security=True";
    public Form1()

        using (SqlConnection sqlConnection = new SqlConnection(connectString))

            SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM [Table]", sqlConnection);

            DataTable dataTable = new DataTable("Table");

            dataGridView1.DataSource = dataTable;
            this.checkBoxAdv1.DataBindings.Add("IntValue", dataTable, "integerValue");
Public Partial Class Form1
    Inherits Form

    Public Shared dataBasePath As String = Path.GetFullPath("..\..\Database1.mdf")
    Public connectString As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" & dataBasePath & ";Integrated Security=True"

    Public Sub New()

        Using sqlConnection As SqlConnection = New SqlConnection(connectString)
            Dim dataAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM [Table]", sqlConnection)
            Dim dataTable As DataTable = New DataTable("Table")
            dataGridView1.DataSource = dataTable
            Me.checkBoxAdv1.DataBindings.Add("IntValue", dataTable, "integerValue")
        End Using
    End Sub
End Class

N > The field binded to IntValue property of CheckBoxAdv should contain -1 or 0 or 1 as value.

DataBinding CheckBoxAdv with Database

View Sample in GitHub