Hi

i am using .net 2.0 & a window application which is connected to sql server
there is checkbox in the application. i want to bind the checkbox with database field which is bit type 1 or 0 please tell how to ?
thanks in advance

Hi,
1) create a query in a dataset

Add query > Use sql statements > Select which returns a single value

the query is something like this:

SELECT valor FROM Table1 where id=@id

valor= is the name of a column in Table1 that DataType is bit.
2) in the form write this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ta As New DataSet1TableAdapters.Table1TableAdapter
'Me.TextBox1.Text = TextBox is where I put the id of row of the Table1 that I want to retrieve information of valor column
        Dim bool As Boolean = ta.ValorBooleano(Me.TextBox1.Text).ToString
        Me.CheckBox1.Checked = bool
    End Sub

I want this help you... (sorry.....my english is not very good)

thanks for ur help
but let me explain the situation more
in my window form there is three tabPages. the first tab page is for filter in which we provide condition to filter data on diff. conditions like id party name, city etc in second tabpage there is datagrid view to show result on base of filter then we select a row from datagrid view which we want to edit then this record is transffered to third tab page in which there are textbox & combobox & checkbox like below

txtPartyName.Text = dt.Rows[0][1].ToString();

txtAddress.Text = dt.Rows[0][2].ToString();

txtCity.Text = dt.Rows[0][3].ToString();

cboCountry.Text = dt.Rows[0][4].ToString();

cboCategory.Text = dt.Rows[0][5].ToString();

txtPhone.Text = dt.Rows[0][6].ToString();

// chkActive.Checked=dt.Rows[0].i

chkActive.DataBindings.Add("Checked", dt, "Active"); 

txtFax.Text = dt.Rows[0][7].ToString();

txtEMail.Text = dt.Rows[0][9].ToString();

txtWebAddress.Text = dt.Rows[0][10].ToString();

tabctrlPublicity.SelectedTab = tabPageAddEdit;

If I understand, you need put the value of a cell of datagridview in the checkBox.....
try with this:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            .
            .
            .
            this. txtPhone.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            this.textBox2.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            this. chkActive.Checked = (Boolean)this.dataGridView1.CurrentRow.Cells[1].Value;
            .
            .
            .

        }

greetings

VB.NET

Me.CheckBox1.DataBindings.Add("Checked", DataTable.Tables(0), "FieldName", True, DataSourceUpdateMode.Never, False)

This article has been dead for over six months. Start a new discussion instead.