专注于技术经验交流

水至清则无鱼、宁静而致远!

技术、经验、学习共同打造网络新生活!
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#与Flash ActionScript 2.0通过xml操作数据库(一)

Posted on 2007-12-24 14:36  小鱼儿  阅读(1443)  评论(0编辑  收藏  举报
c#页面
输出一xml文档在as里边读取xml的值形成列表。

sing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Text;
using OperClass;
using System.Xml;
namespace wqwj.FlashUser
{
 /// <summary>
 /// FlashMessagelist 的摘要说明。获取xml用户短消息信息列表
 /// </summary>
 public class FlashMessagelist : System.Web.UI.Page
 {
  CommClass cc = new CommClass();
  string userid="";
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   //CreateGrid();
   ShowXML();
  }

  #region 输出xml
  /// <summary>
  /// 取出数据导出xml
  /// </summary>
  public void ShowXML()
  {
   userid= Request.QueryString["uid"].ToString();//"7";
   string sqlstr="select top 10 * from message where receiverid='"+userid+"' and type=0 and (delstate='00' or delstate='10') order by id desc";
   DataSet ds = cc.getDS(sqlstr,"message");   
   XmlDocument xmldoc = new XmlDocument () ;//加入XML的声明段落    
   string xml = "<?xml version=\"1.0\" encoding=\"GB2312\"?><list></list>";   
   xmldoc.LoadXml(xml);//加入声明和一个根元素
   if(ds.Tables[0].Rows.Count>0)
   {    

    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
    {
     string g_id=ds.Tables[0].Rows[i]["id"].ToString().Trim();
     string isread=ds.Tables[0].Rows[i]["isread"].ToString().Trim();
     string ishf=ds.Tables[0].Rows[i]["ishf"].ToString().Trim();
     string title=CommClass.strDecode(ds.Tables[0].Rows[i]["title"].ToString().Trim());
     string content=CommClass.strDecode(ds.Tables[0].Rows[i]["content"].ToString().Trim());
     string addtime=CommClass.interceptStr(ds.Tables[0].Rows[i]["addtime"].ToString(),0,10,false);
     string uid=ds.Tables[0].Rows[i]["senderid"].ToString().Trim();
       string nickname=cc.getDataOne("select nickname from users where blocknumber="+uid+"");

     XmlElement xmlelem = xmldoc.CreateElement ("Messages") ;//新建元素

     xmlelem.SetAttribute("m_id",g_id);
     xmlelem.SetAttribute("m_uid",uid);
     xmlelem.SetAttribute("m_title",title );
     xmlelem.SetAttribute("m_nc",nickname);
     xmlelem.SetAttribute("m_content",content);
     xmlelem.SetAttribute("m_addtime",addtime);
                         
     xmldoc.DocumentElement.AppendChild(xmlelem);//把元素加入<list></list>标记中
    }
   }
   Response.Write(xmldoc.InnerXml);
  }
  #endregion
 #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
 }
}
源码下载

New Document