C Sharp语言执行SQL语句的方法
1、 public static bool sqlExecuteNonQuery(string strSql) //执行SQL语句方法,并且无返回值
{
if (m_dbTransaction == null)
{
connectionOpen(); //如果没有事务,则首先打开数据库连接
}
try
{
m_dbCommand.CommandText = strSql;
m_dbCommand.CommandType = CommandType.Text;
m_dbCommand.ExecuteNonQuery(); //执行SQL语句
return true;
}
catch (Exception ex)
{
WriteLog.WriteSQLErrorLog("OracleDBAccess", "sqlExecuteNonQuery", strSql, ex.Message);
throw ex;//抛出异常
}
finally
{
if (m_dbTransaction == null)
{
connectionClose();//关闭数据库连接
}
}
}