MNM MNM - 6 months ago 11
Vb.net Question

Inputting Data into Database and reading it

so i have an SQL database and 2 VB applications, teacher and student application.

In the teacher application, the SQL database is connected with datagridview. In the form there are 10-15 checkboxes. those checkboxes are a set of weak points the teacher can select for a student in their class. for eg- "weak in calculations" etc. I want, when the teacher select the checkboxes, they should be shown in the teacher application in a string form. I think assigning each check box an ID would be a lot better than inputting long strings into the database. when the teacher selects a checkbox, the ID for that checkbox goes into the datagridview selected cell. I am not sure how to seperate each ID in the same cell because the teacher can select multiple checkboxes.

I need help with seperating the IDs and then reading them.

http://www.filedropper.com/sample_18 here is a sample program i made, it shows entering the checkbox id into the datagridview.

Answer

Let's keep it simple. Let's say we have 3 check boxes.

So for saving to db:

dim totalValue as integer = 0
if (chkBox1.checked) then totalValue +=1
if (chkBox1.checked) then totalValue +=2
if (chkBox1.checked) then totalValue +=4

save to db the totalValue

For reading from db:

totalValue = get this value from db
chkBox1.checked = ((totalValue and 1)=1)
chkBox1.checked = ((totalValue and 2)=2)
chkBox1.checked = ((totalValue and 4)=4)
Comments