1

我在我的数据库中使用 sql server

这是代码

private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                    //GlobalClass.dt.Rows[rowId].Delete();
                    //GlobalClass.adap.Update(GlobalClcass.dt);

                cDatabaseSQLServer.Delete("satuan", "WHERE id = " + rowId + "");
                    //this.Close();  
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

public bool Delete(String tableName, String where)
        {
            switch (sqlType)
            {
                case DATABASE_SQL_TYPE.DATABASE_SQL_TYPE_SQLITE:
                    return cSQLite.Delete(tableName, where);
                case DATABASE_SQL_TYPE.DATABASE_SQL_TYPE_MSSQL:
                    return cSQL.Delete(tableName, where);
            }
            return false;
        }

public bool Delete(String tableName, String where)
        {
            Boolean returnCode = true;
            try
            {
                this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));
            }
            catch (Exception fail)
            {
                MessageBox.Show(fail.Message);
                returnCode = false;
            }
            return returnCode;
        }

当我调试应用程序时,删除不起作用并且数据仍然存在于 datagridview 中,如何解决?

4

1 回答 1

2

您的查询是错误的,您有 2 次where,要么更改您的方法调用或查询创建者:

cDatabaseSQLServer.Delete("satuan", "id = " + rowId + ""); //remove where from here

就像这里一样:

this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));
于 2013-07-08T09:05:19.907 回答