sadier

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

要求:
一个文章表:有PostID(文章编号),ParentID(关联了的文章PostID),SourceID(被关联的一篇文章)

原本写了个语句,发觉不能运行。
SELECT PKID, Title, Author, OperateDate, Text, PostID, ParentID, PostID AS SortID
FROM TBL_Post
WHERE (ParentID = 2) AND (PostType = 3 OR
      PostType = 7) AND (DeleteFlag = 0)
UNION
SELECT posta.PKID, posta.Title, posta.Author, posta.OperateDate, posta.Text, posta.PostID,
      posta.ParentID, postb.PostID AS SortID
FROM TBL_Post posta INNER JOIN
      TBL_Post postb ON posta.PostID = postb.SourceID
WHERE posta.ParentID = 2 AND posta.DeleteFlag = 0 AND postb.ParentID = 2 AND
      postb.DeleteFlag = 0
ORDER BY SortID

 

想到dataset. merge,如下成功了

   DataSet ds = new DataSet();
   string strSQL = String.Format(@"select TBL_Config.BlogID  ID , TBL_Config.Author Name
           from TBL_Post,TBL_Config
              where TBL_Post.Operater = TBL_Config.BlogID
             and PostID = {0}  And TBL_Config.BlogID > 2",postID);
   DataTable dt = JumpDbProvider.Select(strSQL);

   dt.PrimaryKey = new  DataColumn[1]{dt.Columns["ID"]};
   ds.Tables.Add(dt.Copy());

   strSQL = String.Format(@" select GroupID ID,GroupName Name
         from TBL_Group, TBL_PostRight
         where TBL_PostRight.TempID = TBL_Group.GroupID
           And IsGroup = 1
           and PostID = {0} AND Active = 1",postID);
   DataTable dtm = JumpDbProvider.Select(strSQL);

   ds.Merge(dtm,false,MissingSchemaAction.Add);

   return ds.Tables[0];

 

posted on 2004-11-18 11:11  毛小华  阅读(2316)  评论(1编辑  收藏  举报