insert checkboxes text?

michkyutie

Member
Joined
Jan 10, 2009
Messages
11
Programming Experience
Beginner
i'm just a beginner in visual basic 2005 express edition, so i need a help. the question is this, how am i going to insert the texts of checkboxes in my table together with other fields in insert into statement. i know, maybe, this is only a easy problem, but i am running out of time. our defense inschool is on feb 4.please help me.

thanks a lot!:eek:
 
The answer is that you wouldn't, or certainly I've never met a situation where you would. The user can't edit the text of a CheckBox. Perhaps you should provide a more complete description of what this app is supposed to do.
 
thanks for the reply..and sorry if i haven't explained it that clear..
my question is, how am i going to insert the checked checkboxes (the texts of the checkboxes) in my table using the "insert into" statement..

hope that was clear...

thanks again...
 
Still, I can't see why you would. I would expect most applications with a database and check boxes to have a boolean column for each check box, so you'd be setting the fields in a row to true or false, not adding multiple strings to a single column.

You've really only restated what you want to do rather than, as I suggested, providing a more complete description of what your app is supposed to do. What do these check boxes represent? There's not much point our explaining to you how to do what you've asked for if what you've asked for is wrong. It's important for us to know the why as well as the what if we're to provide the best advice.
 
thanks for the reply..and sorry if i haven't explained it that clear..
my question is, how am i going to insert the checked checkboxes (the texts of the checkboxes) in my table using the "insert into" statement..

hope that was clear...

thanks again...

Here is a picture of some checkboxes
CheckBoxCheckEvent.PNG


jmc is confused because youre saying you want to insert the "Checkbox1" or "Checkbox2" text.. i.e. you want an SQL that looks like this:

INSERT INTO table(field1, field2) VALUES("Checkbox1", "Checkbox2")

Which will result in a database table that looks like this:


table.field1|table.field2
----------------------
Checkbox1|Checkbox2


Why would anyone want to insert the word "Checkbox1" into a database table, I'm not sure.. but here's how you'd do it:


Dim cmd as New OracleCommand("INSERT INTO table(field1, field2) VALUES:)parameter1, :parameter2")
cmd.Parameters.AddWithValue("parameter1", checkbox1.Text)
cmd.Parameters.AddWithValue("parameter2", checkbox2.Text)


Because you didnt specify what database youre using, I've provided code for Oracle. For more information, read up on the PQ link in my signature. You should also read the DW2 link in my signature, start with the article "Creating a Simple Data App" as it will teach you a better way of doing this coding.
 
Here is a picture of some checkboxes

jmc is confused because youre saying you want to insert the "Checkbox1" or "Checkbox2" text.. i.e. you want an SQL that looks like this:


i'm not saying that i will insert the "checkbox1" to my database...of course i have changed its text..

i have table with columns IDNum, Name, and HouseCondition. i have textboxes for IDNum and Name and checkboxes for HouseCondition. The choices are 'Okay', 'Floood Prone', 'Squatters'. the user can check these three choices at the same time(since they are checkboxes). now, how am i going to insert the checked checkbox to my table together with that IDNum and Name using the insert into statement...(i am using Microsoft Access 2003)...

tnx!
 
The answer is that you wouldn't, or certainly I've never met a situation where you would. The user can't edit the text of a CheckBox. Perhaps you should provide a more complete description of what this app is supposed to do.

i have table with columns IDNum, Name, and HouseCondition. i have textboxes for IDNum and Name and checkboxes for HouseCondition. The choices are 'Okay', 'Floood Prone', 'Squatters'. the user can check these three choices at the same time(since they are checkboxes). now, how am i going to insert the checked checkbox to my table together with that IDNum and Name using the insert into statement...(i am using Microsoft Access 2003)...

tnx!
 
Ahh. Now it starts to make more sense!

I'd actually do this with a number:

1 = OK
2 = Flood Prone
4 = Squatters
8 = Subsiding
16 = Fire Damage

Don't use 0

Now whatever sum of things are ticked, that's what you write into the table

So a house that is status 22 is FireDamage+Subsiding+Squatters, or 7 is OK+FloodProne+Squatters


To decode:

VB.NET:
int valueFromDB = 7

okCheckBox.Checked = ((valueFromDb And 1) = 1)
floodCheckBox.Checked = ((valueFromDb And 2) = 2)


And is a logical op. The result of (7 AND 2) is 2 because 2 is a common component of the sequences 4+2+1 and 2
7 AND 16 on the other hand, would return 0
7 AND 17 would return 1, because they only have 1 in common (4+2+1, 16+1)
So when decoding a numeric flags enum (using one of those would be even better than hardcoded constants - read up on them) like this, the logic is:

If totalValue AND flagValue = flagValue Then flag_is_set Else flag_is_not_set


-

you also have the option of having a HouseFlags table:

HouseID, Flag
1, OK
1, FP
1, Sq
2, FD
2, Su
2, Sq

And a table to decode the flag into a value (or just write the short text into the HouseFlags table.
In which case pushing data in and out of your table requires you to enumerate the flags and insert them one by one

-

If going the second route I'd ditch the checkboxes entirely and have a datagridview - this allows expansion

I'll post an example project as it will be easier than explaining
 

Latest posts

Back
Top