I would like to know how to update a checkbox using an update statement in the code behind.
I am using a gridview with order information with a checkbox to set if the order is completed or not. Initially it is set to false.
I have a dropdownlist with the order id number that I am using in my update statement (the variable I use is OrderID)
I tried this update statement but it seems like it is not working:
strSQL = "UPDATE Order SET OrderCompleted = true WHERE OrderID = " + OrderID;
Can anyone help, I have been researching this for awhile now.
preguntado el 24 de agosto de 12 a las 05:08
Prueba esto: -
strSQL = "UPDATE [Order] SET OrderCompleted = 1 WHERE OrderID = " + OrderID;
In SQL there is no data type for boolean but there is a data type
bit which accepts zero (0) or one (1) but not true or false. As you are using a checkbox so you need to convert boolean value into integer before passing into the query.
Secondly, as mentioned by @nunespascal braces  around Order word because Order is an SQL keyword.
Order is a reserved word in sql. Used with the order by clause to sort rows.
Encapsulate your table and column names with
 if they are keywords.
strSQL = "UPDATE [Order] SET OrderCompleted = 1 WHERE OrderID = " + OrderID + "";