好的,我有以下代码。它做了我想要的一切,除了这一件事。您在哪里看到查询:
string query1 = "UPDATE caregiverdatabse SET child1 = NULL WHERE id='" + selectedCaregiver + "'";
这只能让我将行中的“child1”列设置为空。我希望它能够通过 child1、child2、child3、child4 或 child5(不必像现在这样直接编码)。前面的代码:
string currentChildIndex = "";
string spotOfChange = "";
int index;
string item;
foreach (int i in childrenListBoxDisp.SelectedIndices)
{
item = childrenListBoxDisp.Items[i].ToString();
}
允许我仅删除链接到 MySQL 数据库的 childrenListBoxDisp 中的第一个选定项目,并且仅当它位于 child1 列中时。我希望它能够根据选择的项目删除任何 childX 列。这一切都在我相信的查询中。帮助表示赞赏!
其余代码:
DialogResult dialogResult =
MessageBox.Show("You are about to remove " + item +
" person from the selected caregiver. Continue?", "Are you sure?",
MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
MySqlConnection connection = new MySqlConnection("Server=" + server +
";" + "Port=" + port + ";" + "Database=" + database + ";"
+ "Uid=" + uid + ";" + "Password=" + password + ";");
connection.Open();
string query1 = "UPDATE caregiverdatabse SET child1 = NULL WHERE id='"
+ selectedCaregiver + "'";
childrenListBoxDisp.Items.Clear();
assignNamesToChildList();
Console.WriteLine("Did we get here , clearing list");
using (var command = new MySqlCommand(query1, connection))
{
using (var reader = command.ExecuteReader())
{