public ExeResEdm Add(string tableName, T model, params string[] skipCols) { Dictionary <string, object> dic = DtModelConvert <T> .GetPropertity(model); object[] values = dic.Values.ToArray(); // string idVal = dic.Values.ToArray()[0].ToString(); //SqlParameter[] pms = GetOleDbParameters(dic.Keys.ToList(), dic.Values.ToList());//参数过多,不会影响程序执行的正确性。 for (int i = 0; i < skipCols.Length; i++)//自动增长的列要忽略 { dic.Remove(skipCols[i]); } for (int i = dic.Values.Count - 1; i >= 0; i--)//值为空的不参与 { if (dic.Values.ToList()[i] == null) { dic.Remove(dic.Keys.ToList()[i]); } } ComDBFun ComDBFun = new ComDBFun(DBBaseAttr); string textParas = ComDBFun.GetSQLText(dic.Keys.ToList()); string sql = "insert into " + tableName + textParas; // SqlParameter[] pms = ComDBFun.GetMSOleDbParameters(dic.Keys.ToList(), dic.Values.ToList()); DbParameter[] //pms = ComDBFun.GetOrclOleDbParameters(dic.Keys.ToList(), dic.Values.ToList()); pms = GetDbParametersFromDic(dic); var n = ExecuteNonQuery(sql, pms); return(n); }
public CRUDSql GetInsertSql <M>(M model, string tableName, bool bParameterizedQuery) { Dictionary <string, object> dic = DtModelConvert <T> .GetPropertity(model); ComDBFun ComDBFun = new ComDBFun(DBBaseAttr); string textParas = ComDBFun.GetSQLText(dic.Keys.ToList(), (bParameterizedQuery ? null : dic.Values.ToList())); string sql = "insert into " + tableName + textParas; CRUDSql insertSql = new CRUDSql() { Sql = sql }; if (bParameterizedQuery) { insertSql.PMS = GetDbParametersFromDic(dic); } return(insertSql); }
public ExeResEdm Add(string tableName, T model, DBOperUser dbLogMsg = null, params string[] skipCols) { Dictionary <string, object> dic = DtModelConvert <T> .GetPropertity(model); object[] values = dic.Values.ToArray(); // string idVal = dic.Values.ToArray()[0].ToString(); //SqlParameter[] pms = GetOleDbParameters(dic.Keys.ToList(), dic.Values.ToList());//参数过多,不会影响程序执行的正确性。 for (int i = 0; i < skipCols.Length; i++)//自动增长的列要忽略 { dic.Remove(skipCols[i]); } for (int i = dic.Values.Count - 1; i >= 0; i--)//值为空的不参与 { if (dic.Values.ToList()[i] == null) { dic.Remove(dic.Keys.ToList()[i]); } } ComDBFun ComDBFun = new ComDBFun(DBBaseAttr); string textParas = ComDBFun.GetSQLText(dic.Keys.ToList(), null); string sql = "insert into " + tableName + textParas; DbParameter[] pms = GetDbParametersFromDic(dic); LogTraceEdm logMsg = null; if (dbLogMsg != null) { logMsg = new LogTraceEdm() { LogType = LogType.添加, UserId = dbLogMsg.UserId, UserName = dbLogMsg.UserName, TabOrModu = tableName, }; } var n = ExecuteNonQuery(sql, logMsg, pms); return(n); }