-
Aug 9th, 2019, 04:07 AM
#1
Thread Starter
New Member
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
-
Aug 9th, 2019, 05:18 AM
#2
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.
-
Aug 9th, 2019, 06:09 AM
#3
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.
-
Aug 9th, 2019, 11:21 AM
#4
Thread Starter
New Member
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
-
Aug 10th, 2019, 12:29 AM
#5
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.
-
Aug 13th, 2019, 02:41 PM
#6
Thread Starter
New Member
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
-
Aug 13th, 2019, 02:41 PM
#7
Thread Starter
New Member
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
-
Aug 13th, 2019, 03:59 PM
#8
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.
-
Aug 13th, 2019, 04:50 PM
#9
Thread Starter
New Member
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
-
Aug 13th, 2019, 06:05 PM
#10
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.
-
Aug 13th, 2019, 07:40 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|