Visual Studio 2010中c# 实现通过 关键字段 从数据库表中删除该条记录?求高手解答。
2个回答
展开全部
public bool Delete(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from pro ");
strSql.Append(" where id=@id ");
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "id", DbType.Int32,id);
int rows=db.ExecuteNonQuery(dbCommand);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from pro ");
strSql.Append(" where id=@id ");
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "id", DbType.Int32,id);
int rows=db.ExecuteNonQuery(dbCommand);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
追问
能不能帮忙注释一下,看的不是很懂!!谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询