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:
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.
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.
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.