By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

VB2005- how to manage multiple checkbox result

P: 9
Hi.

How do I insert in a db multiple checkbox results? I have 11 checkboxes, so how to do it in one query? Please :P
Dec 30 '07 #1
Share this Question
Share on Google+
16 Replies


Expert 5K+
P: 8,434
If you give us some idea of how you're interfacing with the database now, to handle a single value, I'm sure we can help you extend it to store multiple values.
Dec 31 '07 #2

P: 3
If you want to use multiple check boxes then first be sure you are using a control array. After that while inserting data take this reference.

If you have 11 controls then

Let check box name be check1
Expand|Select|Wrap|Line Numbers
  1. For I = 0 To 10
  2.   STRA = STRA & "'" & Check1(I).Caption & "'" & ","
  3. Next
  4. STRA = Mid(STRA, 1, Len(STRA) - 1)
  5. STRSQL = "INSERT INTO TABLENAME VALUES('RAM','SHYAM'," & STRA & ")"
  6.  
  7. CN.Execute STRSQL
Thatís it.
If you need more, contact me on <Removed by Moderator>
Dec 31 '07 #3

Expert 5K+
P: 8,434
Thanks for that, yaad.

But please don't post your e-mail address (or anyone else's) in the forum. This is for your protection, from scammers and spammers who may scan the list. If people need to contact you privately, they can send you a private message, or "PM" by clicking on your ID to get to your profile. You can then exchange details privately.

Also, please don't SHOUT when responding to a question. I have converted most of the ALL UPPER CASE TEXT to mixed (or "sentence") case.
Dec 31 '07 #4

Expert 5K+
P: 8,434
Oh, and one more thing. Control arrays were removed after VB6. They're not available in VB 2005. I wish I knew why, as they are an extremely useful feature.
Dec 31 '07 #5

P: 9
Control arrays were removed after VB6. >> okay cause I learned 2005 and I don't know what control arrays are :( . You said to show you how my database is? Well I have one table with 2 text fields, 11 checkboxes and 1 datetime field. All of that I should fill with one button click. In text box I enter the name, I select the date and check specific checkbox so I enter the name, date and value for some of the 11 check box like true.
Dec 31 '07 #6

P: 9
i decide to insert values of all checkboxes at once into table with yes/no field. the questione is how code looks for checkbox control:
"checbox.________???"
Dec 31 '07 #7

Expert 5K+
P: 8,434
... questione is how code looks for checkbox control:
"checbox.________???"
Not sure what code you mean. Do you mean how to insert a checkbox value into SQL to go into a Yes/No field? If so, that's probably quite version-specific. In VB6, I would use the Format() function to format the boolean value as "YES" or "NO".
Jan 1 '08 #8

P: 9
so bad im new so probably i not good explaining, look, i have checkbox on my form, and i want save the users choice or selection, or that checked unchecked value of the checkbox into access database into yes/no table field. it should be quite simple, something like "checbox.checked" or i dont know????:(
Jan 1 '08 #9

P: 9
Dim sql As String = "insert into dnEvidencija (elektroth) values"
& "("+cbElektro.Checked + ")"

this is how it looks in code, it not vorking :(
Jan 2 '08 #10

P: 41
This should do it for you

Expand|Select|Wrap|Line Numbers
  1.             Dim sql As String = "INSERT INTO dnEvidencija " & _
  2.               "(Field_One, Field_Two, Field_Three, Field_Four, Field_Five) Values (" & CheckBox1.Checked & "," & CheckBox2.Checked & "," & CheckBox3.Checked & "," & CheckBox4.Checked & "," & CheckBox5.Checked & ");"

Hope this helps,
Torgg
Jan 2 '08 #11

Expert 5K+
P: 8,434
Just out of curiosity, what do you actually get when you assign the Checked property to a string?
Jan 3 '08 #12

P: 9
Conversion from string "(" to type 'Double' is not valid.
Jan 3 '08 #13

P: 41
Conversion from string "(" to type 'Double' is not valid.
You'll need to post more information then this. Are you getting an error from the code I posted (I tested it and it worked fine)? Did you copy and paste what I posted (just to have a base line of working code)? Please post the modified SQL query youíre having trouble with.

Torgg
Jan 3 '08 #14

Expert 5K+
P: 8,434
Conversion from string "(" to type 'Double' is not valid.
This can't be in response to what I asked, because that was about converting to a string, not from.
Jan 3 '08 #15

P: 9
Torgg you the king! Your code works, he now i can go on with my app development, he sound seriosly, he thanks killer to, it works just fine, isert work, great, you make my day, thanks, manius
Jan 4 '08 #16

Expert 5K+
P: 8,434
Glad we could help out. :)
Jan 5 '08 #17

Post your reply

Sign in to post your reply or Sign up for a free account.