public void Delete(string where, params object[] paramters) { StringBuilder sql = new StringBuilder(); sql.Append("delete from ").Append(type.Name).Append(string.IsNullOrEmpty(where) ? " where " + where : ""); DbHelperSQL.ExcuteNonquery(sql.ToString(), paramters); }
public void Delete(T t, params string[] fieldName) { List <object> paramters = new List <object>(); List <string> pa = new List <string>(); int i = 0; foreach (string name in fieldName) { pa.Add(name + "=@" + i++); paramters.Add(type.GetProperty(name).GetValue(t, null)); } DbHelperSQL.ExcuteNonquery("delete from " + type.Name + (fieldName.Length > 0 ? " where " + string.Join(" and ", pa) : "") , paramters); }
public void Update(T t, string[] wheres, params string[] fields) { StringBuilder sql = new StringBuilder(); StringBuilder pam = new StringBuilder(); List <object> paramters = new List <object>(); sql.Append("update ").Append(type.Name).Append(" set "); if (fields == null) { var i = 0; foreach (PropertyInfo pi in type.GetProperties()) { sql.Append(i == 0 ? "" : ",").Append(pi.Name).Append("=@").Append(i++); paramters.Add(pi.GetValue(t, null)); } if (wheres.Length > 0) { sql.Append(" where "); } foreach (string where in wheres) { sql.Append(where).Append("=@").Append(i++); paramters.Add(type.GetProperty(where).GetValue(t, null)); } } else { var i = 0; foreach (string field in fields) { sql.Append(i == 0 ? "" : ",").Append(field).Append("=@").Append(i++); paramters.Add(type.GetProperty(field).GetValue(t, null)); } if (wheres.Length > 0) { sql.Append(" where 1=1 "); } foreach (string where in wheres) { sql.Append(" and ").Append(where).Append("=@").Append(i++); paramters.Add(type.GetProperty(where).GetValue(t, null)); } } DbHelperSQL.ExcuteNonquery(sql.ToString(), paramters.ToArray()); }
public void Insert(T t, params string[] fields) { StringBuilder sql = new StringBuilder(); StringBuilder pam = new StringBuilder(); List <object> paramters = new List <object>(); sql.Append("insert into ").Append(type.Name).Append("("); if (fields == null) { var i = 0; foreach (PropertyInfo pi in type.GetProperties()) { if (pam.Length != 0) { sql.Append(","); pam.Append(","); } sql.Append(pi.Name); pam.Append("@").Append(i++); paramters.Add(pi.GetValue(t, null)); } } else { sql.Append(fields[0]); pam.Append("@0"); paramters.Add(type.GetProperty(fields[0]).GetValue(t, null)); for (var i = 1; i < fields.Length; i++) { sql.Append(",").Append(fields[i]); pam.Append(",@").Append(i); paramters.Add(type.GetProperty(fields[i]).GetValue(t, null)); } } sql.Append(") values (").Append(pam).Append(")"); DbHelperSQL.ExcuteNonquery(sql.ToString(), paramters.ToArray()); }
public void RefreshStudyPlanStatus(int planId, int attending, int memberId) { DbHelperSQL.ExcuteNonquery("update studyplay set attending= @0 where planid=@1 and memberid=@2", attending, planId, memberId); }