| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 598 人关注过本帖
标题:Web网站中,后置文件使用两种方式保存数据在何区别?请求帮助
只看楼主 加入收藏
soular
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-3-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
Web网站中,后置文件使用两种方式保存数据在何区别?请求帮助
注册页面代码:
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SingUp.aspx.cs" Inherits="SingUp" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   
    <table style="width: 459px; text-align: center ; border:1px #ff000fff solid;">
        <tr>
            <td colspan="3" style="height: 23px;background-color:#3300ff; color: #ffffff; font-family:Microsoft Sans Serif;">
                用户登录</td>
        </tr>
        <tr>
            <td style="width: 101px" align="right">
                用户名:</td>
            <td style="width: 162px">
                <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
            <td style="width: 146px">
                <asp:RequiredFieldValidator ID="rfvUserName" runat="server" ControlToValidate="txtUserName"
                    ErrorMessage="用户名不能为空!"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px" align="right">
                密&nbsp; 码:</td>
            <td style="width: 162px">
                <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox></td>
            <td style="width: 146px">
                <asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword"
                    ErrorMessage="密码不能为空!"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px; height: 18px" align="right">
                请输入密码:</td>
            <td style="width: 162px; height: 18px">
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
            <td style="width: 146px; height: 18px">
                <asp:CompareValidator ID="cvConfimPassword" runat="server" ControlToCompare="txtPassword"
                    ControlToValidate="TextBox1" ErrorMessage="密码不一样!"></asp:CompareValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
            </td>
            <td style="width: 162px">
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="确定" />&nbsp;
                <asp:Button ID="btnCancle" runat="server" Text="取消" /></td>
            <td style="width: 146px">
                </td>
        </tr>
    </table>
    </asp:Content>


这是后置文件代码:            第一种方式可以何存数据
     protected void btnOK_Click(object sender, EventArgs e)
    {
        string path = Server.MapPath("Message.xml");
        if (File.Exists(path))
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);

            XmlElement newElement = xmlDoc.CreateElement("liuyan");
            XmlElement elname = xmlDoc.CreateElement("name");
            XmlElement elpass = xmlDoc.CreateElement("pass");
            XmlElement elconfim = xmlDoc.CreateElement("confimps");


            elname.InnerText = this.txtUserName.Text.Trim();
            elpass.InnerText = this.txtPassword.Text.Trim();
            elconfim.InnerText = this.TextBox1.Text.Trim();

            newElement.AppendChild(elname);
            newElement.AppendChild(elpass);
            newElement.AppendChild(elconfim);

            xmlDoc.DocumentElement.AppendChild(newElement);

            xmlDoc.Save(Server.MapPath("Message.xml"));
            Response.Write("<script>alert('你好')</script>");
        }

    }

    public string ReturnCount()
    {

        string i = string.Empty;
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath("guestbook.xml"));
        XmlNode xmlNode = xmlDoc.DocumentElement.LastChild;
        if (xmlNode != null)
        {
            i = Convert.ToString(Convert.ToUInt32(xmlNode["id"].InnerText) + 1);
        }
        return i;
    }


这种方式为什么不能保存数据
        protected void btnOK_Click(object sender, EventArgs e)
    {
        string path = Server.MapPath("Message.xml");
        if (!File.Exists(path))
        {
            DataTable dt = new DataTable("MessageTable");
            dt.Columns.Add("Id", typeof(Int32));
            dt.Columns.Add("Name", typeof(String));
            dt.Columns.Add("Email", typeof(String));
            dt.Columns.Add("QqNumber", typeof(String));
            dt.Columns.Add("Information", typeof(String));

            dt.Columns[0].AutoIncrement = true;
            dt.Columns[0].AutoIncrementSeed = -1;
            dt.Columns[0].AutoIncrementStep = -1;

            DataRow dr = dt.NewRow();
            dr[1] = this.txtUserName.Text.Trim();
            dr[2] = this.txtPassword.Text.Trim();
            dr[3] = this.TextBox1.Text.Trim();
            dt.Rows.Add(dr);

            DataSet ds = new DataSet("Root");
            ds.Tables.Add(dt);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(ds.GetXml());
            ds.Clear();
            ds.Dispose();
            XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
            //xmlDec.Encoding = "UTF-8";
            //xmlDec.Standalone = "yes";

            XmlElement xmlEleRoot = xmlDoc.DocumentElement;
            xmlDoc.InsertBefore(xmlDec, xmlEleRoot);
            xmlDoc.Save("MessageData.xml");
        }
    }
搜索更多相关主题的帖子: 请求 后置 文件 数据 Web 
2010-03-08 17:38
yms123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:20 
按理说应该能保存的,而且DataSet对象本身就可以直接保存DataSet的数据到XML文件。
2010-03-09 16:20
快速回复:Web网站中,后置文件使用两种方式保存数据在何区别?请求帮助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.077043 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved