CheckBox and DataSet/DataBase

Posted on 2004-11-06
Last Modified: 2010-04-24

This is the first time I'm using the CheckBox Control and have to write it's state to a (boolean) DataSet field .

This is the way I'm doing it:

chbSuspend is the CheckBox' name.

Dim dr As DataRow = DsProducts1.Tables("tProducts").NewRow

        If chbSuspend.CheckState = CheckState.Checked Then
            dr("Discontinued") = chbSuspend.Checked.TrueString
        Else : dr("Discontinued") = chbSuspend.Checked.FalseString
        End If


The updating of the DataSet/DataBase does'nt work. Obviously handling boolean data is the problem.

Can somebody help me? Any help shall be greatly appreciated.

Question by:Ghanisen
    LVL 28

    Accepted Solution

    Here is an example how to write to boolean field in ds

    Public Class Form1
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "
    #End Region

        Private WithEvents myDataTable As New DataTable("Test")
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            DataGrid1.DataSource = myDataTable
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myDataTable.Columns.Add("Forename", System.Type.GetType("System.String"))
            myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean"))
            myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String"))
            myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"})
            myDataTable.Rows.Add(New Object() {"John", False, "Peterson"})
            myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"})
        End Sub
        Private Sub myRowChanging(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Handles myDataTable.RowChanging
        End Sub
        Private Sub myColumnChanging(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging
        End Sub

    End Class


    Author Comment

    Hi iboutchkine,

     I have found a simpler method that works :

    Dim dr As DataRow = DsProducts1.Tables("tProducts").NewRow

    ....... 'Code for other rows

    dr("Discontinued") = chbSuspend.CheckState

    .......'Code for other rows


    But I still have one problem: For the column ("Discontinued") I get in my DataGrid "False" or "True" in English whereas my end users speak French. Do you know how I can get the DataGrid to show "Vrai" and "Faux" instead of "True" and "false"?

    Thanks for your help.

    LVL 28

    Expert Comment

    I am not very familiar with this, but check CultureInfo class

    The CultureInfo class holds culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. This class also provides access to culture-specific instances of DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings.

    something like

     ci = New CultureInfo("en-US")' here use french

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now