I'm stuck with a problem regarding checkboxes from a WPF application to a SQL database.
I've arrived at a point where I can update the value of a specific item into the database but I can only update the value or from 0 to 1 or from 1 to 0, I'm searching for an IF Statement kind of thing, and I think I'm near the solution but the code isn't working and gives me the error" there's an error near =" PLEASE
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
sqliteCon.Open();
if (sqliteCon.State == System.Data.ConnectionState.Open)
{
var currentRowIndex = dataGrid1.Items.IndexOf(dataGrid1.CurrentItem);
//FROM 0 TO 1
// string q = "UPDATE tabList Set selection = '" + 1 + "' WHERE idL="+ (currentRowIndex= currentRowIndex+1);
//TEST4
string q = @"UPDATE tabList
SET selection = (CASE
WHEN tabList.selection.Value = ' 0 '
THEN tabList.selection.Value = ' 1'
ELSE tabList.selection.Value = ' 0 '
END)
WHERE idL = " + (currentRowIndex = currentRowIndex + 1);
SqlCommand cmd = new SqlCommand(q, sqliteCon);
cmd.ExecuteNonQuery();
MessageBox.Show("Dato Modificato");
}
sqliteCon.Close();
}
Please replace this.
string q = @"UPDATE tabList
SET selection = (CASE WHEN " + tabList.selection.Value.ToString() + " = 0 "
+ " THEN 1 ELSE 0 END) WHERE idL = " + (currentRowIndex + 1);
you might be missing the single quote symbol. Try replace it with this.
//TEST4
string q = @"UPDATE tabList
SET selection = (CASE
WHEN tabList.selection.Value = ' 0 '
THEN tabList.selection.Value = ' 1'
ELSE tabList.selection.Value = ' 0 '
END)
WHERE idL = '" + (currentRowIndex = currentRowIndex + 1) + "'";
please let me know if this working. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.