dcsimg
Results 1 to 11 of 11

Thread: how to insert selected items in checkbox list to mysql database in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    5

    how to insert selected items in checkbox list to mysql database in vb.net

    I have a table 'food' that has four columns such protein, carbohydrate, vegetable and menerals.
    I want to create a checkbox list for all columns so that user can select more than one items and submit to mysql database

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

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    Your post is a bit vague but it sounds like maybe you need a DataGridView with four check box columns. More details are in order.

  3. #3
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,968

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    not really clear what your Table looks like
    I created a Checkedlistbox with 5 Items

    this will Insert to a Table with the 5 Fields (Field1,Field2 etc...)
    Code:
     Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
            Dim strSQL As String
            Dim delim As String = ","
            strSQL = "INSERT INTO tbl_testBoolean(Field1 ,Field2,Field3 ,Field4,Field5) VALUES("
    
            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                Dim value As String = CStr(CheckedListBox1.GetItemCheckState(i))
                strSQL = strSQL & "'" & String.Format("{0}", value) & "'" & delim
            Next
            strSQL = strSQL & ")"
            strSQL = strSQL.Remove(strSQL.Length - 2, 1)
            Debug.Print(strSQL)
        End Sub
    the Debug output
    Code:
    INSERT INTO tbl_testBoolean(Field1 ,Field2,Field3 ,Field4,Field5) VALUES('0','1','0','1','0')
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    5

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    the name of my table 'food' which contain the following fields protein, carbohydrate, vegetables. I want to use checkedlistbox to the fields with their examples. eg

    protein
    item1
    item2
    item3
    ...
    itemn

    Carbohydrate
    item1
    item2
    item3

    vegetables
    item1
    item2
    item

    i want to checked items in the above types of food to be submitted to mysql database table 'food'
    pls i need help

  5. #5
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,968

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    doesn't Post#3 help ?

    still not clear what the above is? is that 3 Checkedlistboxes ?
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    5

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    I have three checklist boxes with a table containing three columns. how can I insert the checked items in those checklist boxes to mysql database
    Name:  checklistboxes.jpg
Views: 22
Size:  27.1 KB

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    5

    Resolved Re: how to insert selected items in checkbox list to mysql database in vb.net

    I have three checklist boxes with a table containing three columns. how can I insert the checked items in those checklist boxes to mysql database
    Name:  checklistboxes.jpg
Views: 22
Size:  27.1 KB

  8. #8
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    How do you want to insert the items. Does each checked item have it's own row in the table or do all checked items go in one row? Could a checkedlistbox have multiple items checked or just one per clb? Are these items associated with a person? Does that person have a unique Id? btw - your original post talked about a food table, your last post has nothing to do with food. As you can see noone can help you until you provide a complete explanation of the situation and what your trying to achieve.

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    5

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    it is a similar problem with this.
    each checked list box represents a single field in the database table. Here the table name is radiology_test. The check list box should have multiple items checked and be inserted the database table. These are fields in the table ; ultrasound, CT_scan, MRI_scan

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,598

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    You need to start by designing your database properly. You should have four tables, not one. That data can't be sensibly mapped to a single table. You would need one main table and then three child tables, each with a foreign key to the main table. At least, that's how it sounds to me from your description.
    Last edited by jmcilhinney; Aug 13th, 2019 at 06:08 PM.

  11. #11
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: how to insert selected items in checkbox list to mysql database in vb.net

    Yeah I'd agree with jmc. The way you have it now, the only way it would work would be if only one item from a checkedlistbox was checked. What were you planning on doing if 3 items in the ultrasound clb was checked? You've only provided one field to store that information. What jmc is talking about is called a relational database.

    Tables Columns
    -------- ----------------------------------------------------------------------------
    Patient PatientId FullName

    UltraSound UltrSoundId PatientId Description

    CtScan CTId PatientId Description

    MriScan MriId PatientId Description


    You would also need a table (or 3) to store all the available procedures that you would use to populate the clb's.

    Anyway that one way to store your data.

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