CheckBox and DataSet/DataBase

Hi,

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

        DsProducts1.Tables("tProducts").Rows.Add(dr)

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.

GhanisenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

iboutchkineCommented:
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"})
        myDataTable.AcceptChanges()
    End Sub
    Private Sub myRowChanging(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Handles myDataTable.RowChanging
        MessageBox.Show("RowChanging")
    End Sub
    Private Sub myColumnChanging(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging
        MessageBox.Show("ColumnChanging")
    End Sub

End Class

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GhanisenAuthor Commented:
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

DsProducts1.Tables("tProducts").Rows.Add(dr)

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.
 




0
iboutchkineCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.