首页 > 解决方案 > 如何在 sqlite 中使用 WHERE 语句

问题描述

我已经得到了 sqlite 查询来删除数据库中的条目,单击按钮现在一切正常,我不需要最后有第二个 WHERE 语句。毫无疑问,我需要稍微清理一下我的代码,但我只是想确保它首先工作

        private void btn_Delete_Click(object sender, EventArgs e)
    {
        DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this account?", "Confirm Delete", MessageBoxButtons.YesNo);
        if (dialogResult == DialogResult.Yes)
        {
            connAccount.Open();
            using (SQLiteCommand cmd = connAccount.CreateCommand())
            {

                // adds customers details to the database
                cmd.CommandText = @"DELETE FROM account WHERE accid = '" + Global.selectedAccountID.ToString() + "';";
                MessageBox.Show("Account Deleted", "Account Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmd.ExecuteNonQuery();
                connAccount.Close();

            }

        }
        if(dialogResult == DialogResult.No)
        {
            
        }
        if (cb_active.SelectedIndex == 0)
        {
            active();
        }
        if (cb_active.SelectedIndex == 1)
        {
            inactive();
        }
        else
        {
            showAccounts();
        }
        cb_active.SelectedIndex = -1;
        connAccount.Close();

    }

标签: c#winformssqlite

解决方案


请检查deleteQuery的值是否正确如下:

  1. 复制 deleteQuery 的值
  2. 将值(一个 SQL 脚本)粘贴到 SSMS 中
  3. 在 SSMS 中执行 SQL 脚本并检查它是否运行没有任何错误。

推荐阅读