C# 删除不在c中工作的查询#
我在数据库中使用sql server 这是代码C# 删除不在c中工作的查询#,c#,C#,我在数据库中使用sql server 这是代码 private void btnDelete_Click(object sender, EventArgs e) { try { //GlobalClass.dt.Rows[rowId].Delete(); //GlobalClass.adap.Update(GlobalClcass.dt);
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次
,其中
,请更改您的方法调用或查询创建者:
cDatabaseSQLServer.Delete("satuan", "id = " + rowId + ""); //remove where from here
就在这里:
this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));
看起来您将得到两个
,其中排成一行。还可以使用参数化查询。在Delete
函数中存在很大的安全漏洞。如果我通过怎么办;将所有
作为我的where
参数删除?cDatabaseSQLServer。删除(“satuan”,“where id=“+rowId+”)
似乎在查询中被发送了两次WHERE
关键字。。。。删除中的keyword@all . 我忘记删除查询中的WHERE
。在delete方法中@杰夫·福斯特。我尝试在我的Where参数中传递全部
,但不起作用。