My "problem" table contains categories that are used in a treeview.
The categories are listed in a hierarchical view as in this example
* Test 1
* Test 2
* Test 3
* Test 4
* Test 5
* Test 6
This is stored in the table as
category_Id | category_Descrepription | category_Fullpath | category_ParentId |
---|---|---|---|
1 | Test 1 | Test 1 | |
2 | Test 2 | Test 1\Test2 | 1 |
3 | Test 3 | Test 1\Test3 | 1 |
4 | Test 4 | Test 1\Test3\Test 4 | 3 |
5 | Test 5 | Test 1\Test3\Test 4 | 3 |
6 | Test 6 | Test 1\Test6 | 1 |
I want to be able to delete Category 3 and all its children so I use DELETE FROM categories WHERE category_Fullpath LIKE '%Test1\\Test 3%';
In MySQL (WorkBench and HeidiSQL this works as expected, but if I use my click event that works when I pass the record ID, but it seems to do nothing when I pass the above query.
I checked the output and it produces the correct query, I even copy pasted it and executed it in KeidiSQL and it works, so why not when executed from the code.
My Button_Click event is:
private void ButtonDeleteCategorie(object sender, RoutedEventArgs e)
{
Database dbConnection = new Database();
dbConnection.Connect();
int ID = int.Parse(valueId.Text);
dbConnection.SqlCommand = "DELETE FROM ";
// This works: dbConnection.SqlCommandString = " WHERE category_Id = " + ID + ";";
dbConnection.SqlCommandString = " WHERE category_Fullpath LIKE '%" + valueFullpath.Text.Replace("\\", "\\\\") + dialogCategory.diaLogCategoryValue + "%';";
dbConnection.TableName = DatabaseTable;
dbConnection.UpdateMySqlDataRecord();
_ = dbConnection.LoadMySqlData();
}
My FUnction in my database class
public int UpdateMySqlDataRecord()
{
MySqlCommand SqlCmdUpdate = new MySqlCommand
{
Connection = Database.myConnection,
CommandText = SqlCommand + Connection_Query.database + "." + TableName + SqlCommandString
};
MySqlConnection myConnection = new MySqlConnection(Connection_Query.connectionString);
myConnection.Open();
SqlCmdUpdate.ExecuteNonQuery();
long ID = SqlCmdUpdate.LastInsertedId;
myConnection.Close();
return (int)ID;
}
Can anyone give my a clue where i miss something