Need assistance with checkboxes

Hi All,

I working on an app where I have two checkboxes. I am wondering if my syntax below is correct for writing the entry to the database, especially the last two entries in the SQLExecute statement:

db.SQLExecute("INSERT INTO StudentInfo (FirstName, LastName, Age, DOB, School, Teacher, Grade, DORMONTH, DORDAY, DORYEAR, IEP, MedicalCondition) VALUES (' "+txtFirstName.text+" ', ' "+txtLastName.text+" ', ' "+txtAge.text+" ', ' "+txtDOB.text+" ', ' "+txtSchool.text+" ', ' "+txtTeacher.text+" ', ' "+txtGrade.text+" ', ' "+dropDORMONTH.text+" ', ' "+dropDORDAY.text+" ', ' "+dropDORYEAR.text+" ', ' " +str(CheckBox1.Value)+" ',  ' " +str(CheckBox2.Value)+" ')")

If this is correct, how do I go about fetching the value to place the result in it’s own field in a listbox?

You should, uh, sanitize the SQL before executing it.
You know, just in case.

str() of Checkbox.Value will give you “True” or “False”
Just check the wording when you want to turn it back into a checkbox value.

For an Insert you might want to look into the DatabaseRecord. Then you can use objects.

dim dbr as new DatabaseRecord //other data dbr.booleancolumn("IEP") = CheckBox1.Value dbr.booleancolumn("MedicalCondition") = Checkbox2.value db.insertrecord "StudentInfo", dbr if db.error then //error handling end
Then you’ll use a Recordset to get the out.

dim rs as recordset = db.sqlselect(MyQueryString) if db.error then //error handling end checkbox1.value = rs.field("IEP").booleanvalue checkbox2.value = rs.field("MedicalCondition").BooleanValue

I prefer the object approach because at least the compiler can help you a little.

[quote=224168:@Tim Parnell]You should, uh, sanitize the SQL before executing it.
You know, just in case .[/quote]
haha! Little Bobby :wink:

If the DatabaseRecord does not do the same as a PreparedStetement does I would use PPS instead. That could just be me :slight_smile:

Using DatabaseRecord for inserts is the same as using a PreparedStatement.

Hi Tim,

What would be the proper wording to write the value to the database. I have tried just about every combo I can think of and I can’t quite get it to work.

Hi All,

Here is the syntax I am using to try and populate the listbox with the results of the database entry. Is this correct:

StudentList.Cell(StudentList.LastIndex, 11) = rs.Field(“IEP”).BooleanValue

If so, I believe it is just the SQLExecute wording that needs correction.

Many thanks for the replies thus far.

Roger

Hi All,

I think I got it figured out.

Thanks.

Roger

Checkbox.value returns a boolean value, but the (true or false) values passed to the SQL query should not be passed as strings. You should remove the quotes around them.

If field chkbox is boolean,

CORRECT:

INSERT INTO mytable (chkbox) VALUES (true) 

This statement inserts a record with a TRUE value in the field chkbox.

INCORRECT:

 INSERT INTO mytable (chkbox) VALUES ("true")

This statement in mySQL actually insert a FALSE value, because “true” quoted is a string, not a boolean, and results in false.
Depending on the database engine you could obtain an insert error.