public string InsertMenu(IdentityMenu identity) { //Common syntax var conn = new SqlConnection(_connectionString); var sqlCmd = @"Menu_Insert"; //For parameters var parameters = new Dictionary <string, object> { { "@ParentId", identity.ParentId }, { "@Area", identity.Area }, { "@Name", identity.Name }, { "@Title", identity.Title }, { "@Desc", identity.Desc }, { "@Action", identity.Action }, { "@Controller", identity.Controller }, { "@Visible", identity.Visible }, { "@Authenticate", identity.Authenticate }, { "@CssClass", identity.CssClass }, { "@SortOrder", identity.SortOrder }, { "@AbsoluteUri", identity.AbsoluteUri }, { "@Active", identity.Active }, { "@IconCss", identity.IconCss }, }; try { MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters); } catch (Exception ex) { var strError = "Failed to execute Menu_Insert. Error: " + ex.Message; throw new CustomSQLException(strError); } return(string.Empty); }
public int ExecuteText(string connection_string, MsDatParameters db_params, params string[] command_texts) { var _result = 0; using (SqlConnection _sqlconn = new SqlConnection(connection_string)) { _sqlconn.Open(); SqlTransaction transaction = _sqlconn.BeginTransaction(); try { for (int i = 0; i < command_texts.Length; i++) { if (command_texts[i] != null && command_texts[i] != "") { MsSqlHelper.ExecuteNonQuery(transaction, CommandType.Text, command_texts[i], (SqlParameter[])db_params); _result++; } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _result = -1; throw new Exception("ExecuteText", ex); } finally { _sqlconn.Close(); } } return(_result); }
public bool Update(IdentityProject identity) { var sqlCmd = @"Project_Update"; var strNow = DateTime.Now.ToString("dd/mm/yyyy h:mm"); var parameters = new Dictionary <string, object> { { @"Id", identity.Id }, { @"Code", identity.Code }, { @"ProjectCategoryId", identity.ProjectCategoryId }, { @"CompanyId", identity.CompanyId }, { @"Name", identity.Name }, { @"ShortDescription", identity.ShortDescription }, { @"Detail", identity.Detail }, { @"BeginDate", identity.BeginDate }, { @"FinishDate", identity.FinishDate }, { @"CreatedBy", identity.CreatedBy }, { @"CreatedDate", strNow }, { @"Status", identity.Status }, }; try { using (var conn = new SqlConnection(_connectinString)) { MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters); } } catch (Exception ex) { var strError = "Failed to execute Project_Update. Error: " + ex.Message; throw new CustomSQLException(strError); } return(true); }
public bool Delete(int Id) { var sqlCmd = @"Project_Delete"; var parameters = new Dictionary <string, object> { { @"Id", Id } }; try { using (var conn = new SqlConnection(_connectinString)) { MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters); } } catch (Exception ex) { var strError = "Failed to execute Project_Delete. Error: " + ex.Message; throw new CustomSQLException(strError); } return(true); }
public static int ExecuteNonQuery(string cmdText) { int re = 0; DateTime dt1 = DateTime.Now; try { //SMSGLog.Error(cmdText); SqlErrMsg = ""; re = MsSqlHelper.ExecuteNonQuery(ConnectionstringLocalTransaction, CommandType.Text, cmdText, null); if ((DateTime.Now - dt1).TotalMilliseconds > 3000) { SMSLog.Debug("SqlDBExec =>ExecuteNonQuery 耗时:" + (DateTime.Now - dt1).TotalMilliseconds + "毫秒,result=" + re + ",sql=" + cmdText); } return(re); } catch (SqlException ex) { SqlErrMsg = ex.Message; SMSLog.Error("SqlDBExec =>ExecuteNonQuery Exception:" + cmdText); SMSLog.Error("SqlDBExec =>ExecuteNonQuery Exception: ", ex.Message); } return(0); }
/// <summary> /// /// </summary> /// <param name="connection_string"></param> /// <param name="stored_procedure_name"></param> /// <param name="args"></param> /// <returns></returns> public int ExecuteProc(string connection_string, string stored_procedure_name, params object[] args) { return(MsSqlHelper.ExecuteNonQuery(connection_string, stored_procedure_name, args)); }
public int ExecuteText(string connection_string, string command_text, MsDatParameters db_params) { return(MsSqlHelper.ExecuteNonQuery(connection_string, CommandType.Text, command_text, (SqlParameter[])db_params)); }
//----------------------------------------------------------------------------------------------------------------------------- /// ExecuteText //----------------------------------------------------------------------------------------------------------------------------- public int ExecuteText(string connection_string, string command_text) { return(MsSqlHelper.ExecuteNonQuery(connection_string, CommandType.Text, command_text)); }