private bool Execute4NewsPublicTypes(int id, List<int> newsTypes) { bool ret = false; List<CommandInfo> strSqlNewsTypes = new List<CommandInfo>(); try { string delSql = "delete from T_ADM_NewsPublicTypes where ID=@ID \n"; SqlParameter[] cmdParmsDel = new SqlParameter[1]; cmdParmsDel[0] = new SqlParameter("@ID ", id); strSqlNewsTypes.Add(new CommandInfo(delSql, cmdParmsDel)); foreach (var i in newsTypes) { string insertSql = "insert into T_ADM_NewsPublicTypes values (@ID, @Type) \n"; SqlParameter[] cmdParmsInsert = new SqlParameter[2]; cmdParmsInsert[0] = new SqlParameter("@ID ", id); cmdParmsInsert[1] = new SqlParameter("@Type ", i); strSqlNewsTypes.Add(new CommandInfo(insertSql, cmdParmsInsert)); } DbPortalHelper.ExecuteSqlTran(strSqlNewsTypes); ret = true; } catch (Exception) { ret = false; } return ret; }
public List<int> Query4NewsPublicTypes(int id) { List<int> ret = new List<int>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select NewsType from T_ADM_NewsPublicTypes where ID=@ID \n"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = id; DataSet ds = DbPortalHelper.Query(strSql.ToString(), parameters); var dt = ds.Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { var strType = dt.Rows[i]["NewsType"].ToString(); if (!string.IsNullOrWhiteSpace(strType)) { ret.Add(int.Parse(strType)); } } return ret; }