SqlDatabase m_db = DatabaseFactory.CreateDatabase("数据库连接串配置节名");标签:string,ExecuteNonQuery,cmd,查询,参数,sql,pars,企业库 From: https://blog.51cto.com/xxjjing/5805034
/// <summary>
/// 执行带有查询参数的sql语句,返回受影响行数
/// </summary>
/// <param name="sql">待执行的sql语句</param>
/// <param name="pars">参数列表</param>
public int ExecuteNonQuery(string sql, params IDataParameter[] pars)
{
if (string.IsNullOrEmpty(sql))
throw new Exception("查询脚本为空");
using (DbCommand cmd = m_db.GetSqlStringCommand(sql))
{
cmd.Parameters.AddRange(pars);
int n = m_db.ExecuteNonQuery(cmd);
return n;
}
}
/// <summary>
/// 执行带有事务的sql语句,返回受影响行数
/// </summary>
/// <param name="cmdTran">带有事务处理的command 对象</param>
/// <param name="sql">待执行的sql语句</param>
/// <param name="pars">参数列表</param>
public int ExecuteNonQuery(IDbCommand cmdTran, string sql, params IDataParameter[] pars)
{
if (string.IsNullOrEmpty(sql))
throw new Exception("查询脚本为空");
using (DbCommand cmd = (DbCommand) cmdTran)
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
cmd.Parameters.AddRange(pars);
return cmdTran.ExecuteNonQuery();
}
}