UPDATE a boolean syntax?

I am using lots of checkbox objects which are all Saving to the database and reading back into the Checkbox objects correctly, however I cannot get the UPDATE SQL command to work. What is the correct way to write this code? This is what I have till now:

db.ExecuteSQL("UPDATE Stories SET chkForshadowingStep1 = '" + CCStep1ActionApplied.chkForshadowingStep1.getBoolean + "' WHERE ID = " + StoryID_Selected)

I am getting this error message:

In the DB table, the column for the checkbox is defined as a TEXT type.

You’ve seriously got to stop ignoring everyone. As a prepared statement this is as easy as it gets.

db.ExecuteSQL("UPDATE Stories SET chkForshadowingStep1 = ? WHERE ID = ?", chkForshadowingStep1.Value, StoryIDAsIntegerLikeItShouldBe)

5 Likes

Your code is:

db.ExecuteSQL("UPDATE Stories SET chkForshadowingStep1 = '" + CCStep1ActionApplied.chkForshadowingStep1.getBoolean + "' WHERE ID = " + StoryID_Selected)

The column type is set to TEXT but in the query you pass a Boolean:

CCStep1ActionApplied.chkForshadowingStep1.getBoolean // .getBoolean

Thus the error message.

I used the </> button to format the code as you has been suggested a few times.

Exact same error than in your other post :roll_eyes:

Sorry if I am giving the impression that I’m ignoring someone, I am trying to learn things maybe slower than expected. I will have a look at prepared Statements, thanks for your help.

How is the data stored in your database? 1/0, Y/N, TRUE/FALSE? If you’re building your own query string, you need to know that and convert to the right string version of your boolean value, so the database can make sense of it. If you use a prepared statement, you don’t have to think about it.

Also, how do you store the data in the first place? That could help us direct you to the correct syntax. If you’re using a DatabaseRecord/DatabaseRow, it’s using a prepared statement behind the scenes, so updating with a prepared statement would be the most consistent approach.