public bool ExecStoredProcedure(ExecCommandEventHanler exec) { SqlConnection conn = new SqlConnection(FDBConnectstring); conn.Open(); try { SqlCommand sqlComm = new SqlCommand(); sqlComm.Connection = conn; if (exec != null) { exec(sqlComm); } return(true); } catch (Exception ex) { FErrMsg = ex.Message; return(false); } finally { conn.Close(); } }
/// <summary> /// 执行一个sql脚本修改 /// </summary> /// <param name="sql">脚本</param> /// <param name="ErrMsg">错误消息</param> /// <returns>bool</returns> public bool ExecSql(string sql, ExecCommandEventHanler exec, ExecCommandEventHanler exec2 = null) { try { if (FConn.State == ConnectionState.Closed) { FConn.Open(); } SqlCommand sqlComm = new SqlCommand(); sqlComm.Connection = FConn; sqlComm.CommandText = sql; if (exec != null) { exec(sqlComm); } sqlComm.ExecuteNonQuery(); if (exec2 != null) { exec2(sqlComm); } return(true); } catch (Exception ex) { FErrMsg = ex.Message; return(false); } }
/// <summary> /// 执行一个sql脚本修改 /// </summary> /// <param name="sql">脚本</param> /// <param name="ErrMsg">错误消息</param> /// <returns>bool</returns> public bool ExecSql(string sql, ExecCommandEventHanler exec, ExecCommandEventHanler exec2 = null) { SqlConnection conn = new SqlConnection(FDBConnectstring); conn.Open(); try { SqlCommand sqlComm = new SqlCommand(); sqlComm.Connection = conn; sqlComm.CommandText = sql; if (exec != null) { exec(sqlComm); } sqlComm.ExecuteNonQuery(); if (exec2 != null) { exec2(sqlComm); } return(true); } catch (Exception ex) { FErrMsg = ex.Message; return(false); } finally { conn.Close(); } }
public bool ExecStoredProcedure(ExecCommandEventHanler exec) { try { if (FConn.State == ConnectionState.Closed) { FConn.Open(); } SqlCommand sqlComm = new SqlCommand(); sqlComm.Connection = FConn; if (exec != null) { exec(sqlComm); } return(true); } catch (Exception ex) { FErrMsg = ex.Message; return(false); } }