PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2017 [RESOLVED] Save Yes/No combobox as Bit in Database-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Save Yes/No combobox as Bit in Database

  1. #1

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    827

    Resolved [RESOLVED] Save Yes/No combobox as Bit in Database

    Hi,

    I have created a SQL database table and some fields is data type "bit".

    For one of the bit columns:

    In my application I can see in my dataset that the data type is System.Boolean (is what I want so this is correct)

    Now I drag that field to my userform as a combo box (default was checkbox) and create unbound list YES, NO for the combo.

    This is where I am stuck. I want to associate 1's and 0's or TRUE/FALSE corresponding to YES, NO.

    Can someone please tell me what to do?

    Thanks!!
    Last edited by schoemr; Dec 7th, 2018 at 02:05 AM.
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,634

    Re: Save Yes/No combobox as Bit in Database

    Don't use an unbound ComboBox. Start by defining a type with a Boolean property and a String property:
    vb.net Code:
    1. Public Class FlagListItem
    2.     Public Property Flag As Boolean
    3.     Public Property Text As String
    4. End Class
    Now create a list of items of that type:
    vb.net Code:
    1. Dim flagListItems As New List(Of FlagListItem) From {New FlagListItem With {.Flag = True, .Text = "Yes"},
    2.                                                      New FlagListItem With {.Flag = False, .Text = "No"}}
    and bind it to your ComboBox:
    vb.net Code:
    1. With ComboBox1
    2.     .DisplayMember = "Text"
    3.     .ValueMember = "Flag"
    4.     .DataSource = flagListItems
    5. End With
    You can then bind your child list to the SelectedValue property of the ComboBox, just as you would for a foreign key column with the parent list bound to the ComboBox. It's the exact same principle.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    827

    Re: Save Yes/No combobox as Bit in Database

    Hi John,

    Thank you very much for this. It is also giving me some other ideas now!!
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width