Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Checkbox binding property

I am using Visual Basic.NET 2003. I am using an access Database using the oledbdataadaptor / connection. In my access database I have a bunch of yes/no datatypes that I need to bind with checkboxes in my visualbasic form. After I configure the dataadaptor and then proceed to create the dataset, I get an (1181): 'Convert' is not a member of 'Boolean' error message within my datasetfile.vb file. In order to rid of this error message I have to replace all instances of system.convert.dbnull to convert.dbnull. These SHOULD NOT be DBnull! The code that has the error message is generated by .NET when I generate my dataset. In my form load I have the binding code to bind the controls. I'm able to bind to textboxes without any problems with the "Text" property in my code. However when I use try to use the "Text" property for the binding of checkboxes it won't read or write the boolean values. When I try changing the checkbox binding property to "checked" I get an error message stating that I cannot cast DBnull to other types. Now please don't be confused as to WHY I would want these database values DBNULL, I don't want them DBnull. They should either be 0 or 1 / True or False respectively.
In conclusion I'm wondering what I need to do in order to get these checkboxes to bind correctly so that they are read or wrote correctly. As of right now (with the "Text" binding property) when I select a checkbox and write back to the database, its value remains 0, when in fact it should be 1. When I have the "Checked" binding property it throws an invalid cast exception. Is it the vb.net code that is generated when I create my dataset or is it my control binding code, or what? THe code is below as followed.

VB.NET generated code for the created dataset:

Public Function IsBatteryNull() As Boolean
Return Me.IsNull(Me.tableEquipment_Service_Log.BatteryColumn)
End Function

Public Sub SetBatteryNull()
Me(Me.tableEquipment_Service_Log.BatteryColumn) = System.Convert.DBNull 'THIS IS THE LINE THAT HAS the error message.
End Sub


Control binding code in frmload:

dim pbndtemp1 as binding
pbndtemp1 = New Binding("text", pdtscanner, "Battery")
CheckBox1.DataBindings.Add(pbndtemp1)


Comments

  • btsebbtseb Member Posts: 67
    : I am using Visual Basic.NET 2003. I am using an access Database using the oledbdataadaptor / connection. In my access database I have a bunch of yes/no datatypes that I need to bind with checkboxes in my visualbasic form. After I configure the dataadaptor and then proceed to create the dataset, I get an (1181): 'Convert' is not a member of 'Boolean' error message within my datasetfile.vb file. In order to rid of this error message I have to replace all instances of system.convert.dbnull to convert.dbnull. These SHOULD NOT be DBnull! The code that has the error message is generated by .NET when I generate my dataset. In my form load I have the binding code to bind the controls. I'm able to bind to textboxes without any problems with the "Text" property in my code. However when I use try to use the "Text" property for the binding of checkboxes it won't read or write the boolean values. When I try changing the checkbox binding property to "checked" I get an error message stating that I cannot cast DBnull to other types. Now please don't be confused as to WHY I would want these database values DBNULL, I don't want them DBnull. They should either be 0 or 1 / True or False respectively.
    : In conclusion I'm wondering what I need to do in order to get these checkboxes to bind correctly so that they are read or wrote correctly. As of right now (with the "Text" binding property) when I select a checkbox and write back to the database, its value remains 0, when in fact it should be 1. When I have the "Checked" binding property it throws an invalid cast exception. Is it the vb.net code that is generated when I create my dataset or is it my control binding code, or what? THe code is below as followed.
    :
    : VB.NET generated code for the created dataset:
    :
    : Public Function IsBatteryNull() As Boolean
    : Return Me.IsNull(Me.tableEquipment_Service_Log.BatteryColumn)
    : End Function
    :
    : Public Sub SetBatteryNull()
    : Me(Me.tableEquipment_Service_Log.BatteryColumn) = System.Convert.DBNull 'THIS IS THE LINE THAT HAS the error message.
    : End Sub
    :
    :
    : Control binding code in frmload:
    :
    : dim pbndtemp1 as binding
    : pbndtemp1 = New Binding("text", pdtscanner, "Battery")
    : CheckBox1.DataBindings.Add(pbndtemp1)
    :
    :
    :
    The "text" part of the binding refers to the field of the control you are binding to. Tus since checkboxes do not have a "text" field you cannot bind to it. Try binding to the "checked" field
  • jt_muzixjt_muzix Member Posts: 1
    : : I am using Visual Basic.NET 2003. I am using an access Database using the oledbdataadaptor / connection. In my access database I have a bunch of yes/no datatypes that I need to bind with checkboxes in my visualbasic form. After I configure the dataadaptor and then proceed to create the dataset, I get an (1181): 'Convert' is not a member of 'Boolean' error message within my datasetfile.vb file. In order to rid of this error message I have to replace all instances of system.convert.dbnull to convert.dbnull. These SHOULD NOT be DBnull! The code that has the error message is generated by .NET when I generate my dataset. In my form load I have the binding code to bind the controls. I'm able to bind to textboxes without any problems with the "Text" property in my code. However when I use try to use the "Text" property for the binding of checkboxes it won't read or write the boolean values. When I try changing the checkbox binding property to "checked" I get an error message stating that I cannot cast DBnull to other types. Now please don't be confused as to WHY I would want these database values DBNULL, I don't want them DBnull. They should either be 0 or 1 / True or False respectively.
    : : In conclusion I'm wondering what I need to do in order to get these checkboxes to bind correctly so that they are read or wrote correctly. As of right now (with the "Text" binding property) when I select a checkbox and write back to the database, its value remains 0, when in fact it should be 1. When I have the "Checked" binding property it throws an invalid cast exception. Is it the vb.net code that is generated when I create my dataset or is it my control binding code, or what? THe code is below as followed.
    : :
    : : VB.NET generated code for the created dataset:
    : :
    : : Public Function IsBatteryNull() As Boolean
    : : Return Me.IsNull(Me.tableEquipment_Service_Log.BatteryColumn)
    : : End Function
    : :
    : : Public Sub SetBatteryNull()
    : : Me(Me.tableEquipment_Service_Log.BatteryColumn) = System.Convert.DBNull 'THIS IS THE LINE THAT HAS the error message.
    : : End Sub
    : :
    : :
    : : Control binding code in frmload:
    : :
    : : dim pbndtemp1 as binding
    : : pbndtemp1 = New Binding("text", pdtscanner, "Battery")
    : : CheckBox1.DataBindings.Add(pbndtemp1)
    : :
    : :
    : :
    : The "text" part of the binding refers to the field of the control you are binding to. Tus since checkboxes do not have a "text" field you cannot bind to it. Try binding to the "checked" field
    :
    I've tried the "checked" binding property. I mentioned this in my message. When I use the "checked" property I recieve an invalid cast exception stating that I cannot cast a dbnull to other types. I get this error message when I'm using a datatable as the source. However when I use a new instance of the actual dataset while using the "Checked" property, no errors, however it doesn't read or write to the Database. I've been over this a lot. Any ideas on WHAT I'm doing wrong here?
    Thanks
    Jason
  • btsebbtseb Member Posts: 67
    : : : I am using Visual Basic.NET 2003. I am using an access Database using the oledbdataadaptor / connection. In my access database I have a bunch of yes/no datatypes that I need to bind with checkboxes in my visualbasic form. After I configure the dataadaptor and then proceed to create the dataset, I get an (1181): 'Convert' is not a member of 'Boolean' error message within my datasetfile.vb file. In order to rid of this error message I have to replace all instances of system.convert.dbnull to convert.dbnull. These SHOULD NOT be DBnull! The code that has the error message is generated by .NET when I generate my dataset. In my form load I have the binding code to bind the controls. I'm able to bind to textboxes without any problems with the "Text" property in my code. However when I use try to use the "Text" property for the binding of checkboxes it won't read or write the boolean values. When I try changing the checkbox binding property to "checked" I get an error message stating that I cannot cast DBnull to other types. Now please don't be confused as to WHY I would want these database values DBNULL, I don't want them DBnull. They should either be 0 or 1 / True or False respectively.
    : : : In conclusion I'm wondering what I need to do in order to get these checkboxes to bind correctly so that they are read or wrote correctly. As of right now (with the "Text" binding property) when I select a checkbox and write back to the database, its value remains 0, when in fact it should be 1. When I have the "Checked" binding property it throws an invalid cast exception. Is it the vb.net code that is generated when I create my dataset or is it my control binding code, or what? THe code is below as followed.
    : : :
    : : : VB.NET generated code for the created dataset:
    : : :
    : : : Public Function IsBatteryNull() As Boolean
    : : : Return Me.IsNull(Me.tableEquipment_Service_Log.BatteryColumn)
    : : : End Function
    : : :
    : : : Public Sub SetBatteryNull()
    : : : Me(Me.tableEquipment_Service_Log.BatteryColumn) = System.Convert.DBNull 'THIS IS THE LINE THAT HAS the error message.
    : : : End Sub
    : : :
    : : :
    : : : Control binding code in frmload:
    : : :
    : : : dim pbndtemp1 as binding
    : : : pbndtemp1 = New Binding("text", pdtscanner, "Battery")
    : : : CheckBox1.DataBindings.Add(pbndtemp1)
    : : :
    : : :
    : : :
    : : The "text" part of the binding refers to the field of the control you are binding to. Tus since checkboxes do not have a "text" field you cannot bind to it. Try binding to the "checked" field
    : :
    : I've tried the "checked" binding property. I mentioned this in my message. When I use the "checked" property I recieve an invalid cast exception stating that I cannot cast a dbnull to other types. I get this error message when I'm using a datatable as the source. However when I use a new instance of the actual dataset while using the "Checked" property, no errors, however it doesn't read or write to the Database. I've been over this a lot. Any ideas on WHAT I'm doing wrong here?
    : Thanks
    : Jason
    :

    In checking the Microsoft Knowledge Base I found that there is a reported bug with respect to this issue:

    http://support.microsoft.com/?scid=kb;en-us;326440&spid=2965&sid=global

    You need to add code similar to this example to the end of your binding procdeure:

    [code]
    If dt.Columns("Discontiued").DefaultValue Is System.DBNull.Value Then
    dtColumns("Discontinued").DefaultValue = False [green]'or True if is should be checked[/green]
    End If[/code]
Sign In or Register to comment.