删除查询在c#中不起作用
本文关键字:不起作用 查询 删除 | 更新日期: 2023-09-27 18:21:21
我在数据库中使用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中,如何修复?
您的查询是错误的,您有2次where
,要么更改方法调用,要么更改查询创建者:
cDatabaseSQLServer.Delete("satuan", "id = " + rowId + ""); //remove where from here
就在这里:
this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));