示例#1
0
        public static Content GetContentById(int topicid)    //外键的处理
        {
            string sql = "select * from BBS_Topic where TopicID=@TopicID";
            int    userid;
            int    classid;

            using (SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@TopicID", topicid)))
            {
                if (reader.Read())
                {
                    Content content = new Content();
                    content.Topicid    = (int)reader["TopicID"];
                    content.Title      = (string)reader["Title"];
                    content.Isclose    = (string)reader["IsClose"];
                    content.Contentery = (string)reader["Contentery"];
                    content.Createdon  = (DateTime)reader["CreatedOn"];
                    content.Repliedon  = (DateTime)reader["RepliedOn"];
                    userid             = (int)reader["UserID"];
                    classid            = (int)reader["ClassID"];
                    reader.Close();
                    content.Contentclass = CCService.GetContentclassById((int)reader["ClassID"]); //外键的处理
                    content.User         = UserService.GetUserById1((int)reader["UserID"]);       //外键的处理
                    return(content);
                }
                else
                {
                    reader.Close();
                    return(null);
                }
            }
        }
示例#2
0
        private static IList <Content> GetContentALL(string safeSql)
        {
            List <Content> list  = new List <Content>();
            DataTable      table = DBHelper.GetDataSet(safeSql);

            foreach (DataRow row in table.Rows)
            {
                Content content = new Content();
                content.Topicid      = (int)row["TopicID"];
                content.Title        = (string)row["Title"];
                content.Isclose      = (string)row["IsClose"];
                content.Contentery   = (string)row["Contentery"];
                content.Createdon    = (DateTime)row["CreatedOn"];
                content.Repliedon    = (DateTime)row["RepliedOn"];
                content.Replycount   = (int)row["ReplyCount"];
                content.Contentclass = CCService.GetContentclassById((int)row["ClassID"]); //外键的处理
                content.User         = UserService.GetUserById1((int)row["UserID"]);       //外键的处理

                list.Add(content);
            }
            return(list);
        }