C#與Flash ActionScript 2.0通過xml操作資料庫(一)

來源:互聯網
上載者:User
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 Form設計器產生的程式碼
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 該調用是 ASP.NET Web Form設計器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 設計器支援所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
 }
}
源碼下載

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.