public bool Add(CategoryItems entity) { //拼接SQL语句 string cmd = entity.GetInsertSql(); //读取属性名 Dictionary <string, object> properties = entity.GetAllPorpertiesNameAndValues(); List <SqlParameter> ps = new List <SqlParameter>(); foreach (KeyValuePair <string, object> item in properties) { string paramName = "@" + item.Key; string field = "{" + item.Key + "}"; if (cmd.Contains(field)) { cmd = cmd.Replace(field, paramName); //获取参数的数据类型 SqlParameter p = new SqlParameter(paramName, item.Value == null?DBNull.Value:item.Value); ps.Add(p); } } SqlCmdHelper helper = new SqlCmdHelper() { SqlConnString = SqlConnString }; return(helper.ExcuteNoQuery(cmd, ps.ToArray()) > 0); }