CheckBox question

W

Woody Splawn

I have a winform with a checkbox on it. The editor is named CBXE30.
I have it bound to a bit field in SQL Server 2000. In design mode, in the
databindings section of the control I have the Checked property set to
DsMain1 - Contracts.E30.

The binding appears to be working correctly because if I bring a certain
record to the WinForm where I know that the E30 Column in the Database is
equal to 1, the CBXE30 checkbox on the form appears checked. If I bring it
to the screen and I know ahead of time that the E30 column in the db equals
0, the CBXE30 checkbox appears unchecked.

The problem comes when I make a change to the CheckBox. If I check or
uncheck it and try to post the record to the database I get an error message
of "Error converting the VarChar value T to a column of data type bit".

What's going on here? Do I need to write some code in one or more of the
events associated with the checkbox. If so, what event and what code should
I write. I would like this to be a 3 state checkbox.
 
P

Peter Huang

Hi Woody,

Based on my understanding ,you bind a checkbox onto a bit type field. When
you update the change to the database,you encounter the "Error converting
the VarChar value T to a column of data type bit" error.

Here is my code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DataSet11)
'Databinding to the checkbox
Me.CheckBox1.DataBindings.Add("Checked", Me.DataSet11,
"Table1.BITDATA")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
BindingContext(DataSet11, "Table1").EndCurrentEdit()
Me.SqlDataAdapter1.Update(Me.DataSet11)
End Sub

This is the schema of my dataset ( The dataset has two field, one is ID (
int), the other is BITDATA(bit).

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="DataSet1"
targetNamespace="http://www.tempuri.org/DataSet1.xsd"
xmlns:mstns="http://www.tempuri.org/DataSet1.xsd"
xmlns="http://www.tempuri.org/DataSet1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="DataSet1" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="BITDATA" type="xs:boolean" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:primaryKey="true">
<xs:selector xpath=".//mstns:Table1" />
<xs:field xpath="mstns:ID" />
</xs:unique>
</xs:element>
</xs:schema>

If you hope the checkbox to a three state, you may need to bind the
checkstate to a int type, since the bit type can not be binded to the
checkstate which is a enumerate type with three values.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top