网站首页 > 网络编程教程 > XML教程 > 從無到有實現一個xml數據庫登錄驗証

從無到有實現一個xml數據庫登錄驗証

  • 作者:互联网
  • 时间:2009-07-07 16:20:36

    這兩天﹐對xml作為數據庫產生了興趣﹐找了一些資料﹐也搞出了一點眉目﹐在這里記錄一下。算是對自己學習xml的一個小結吧。技朮內容不是很強﹐高手大俠們就不需看了。呵呵....
    不多說廢話﹐咱們程序員最注重的是實用性﹐以下就將本人自己產生xml數據庫﹐然后再登錄驗証的全過程共享出來。
    首先﹐請建立一個windows專案,然后從工具箱中拖兩個TextBox﹐ID分別為UserName 和UserPwd,然后再拖兩個Button出來﹐ID分別為btnOK和bt***n.Text屬性分別設為"驗証"和"建立"。
然后在btnGen的click事件中加入如下代碼﹐產生一個xml文件﹐作為數據庫﹕
    XmlDocument xd = new XmlDocument();
    XmlNode xnDec = xd***eateNode(Xm***deType.XmlDeclaration, "", "");
    XmlElement xeRoot = xd***eateElement("Users");
    xd***pendChild(xnDec);
    xd***pendChild(xeRoot);

    XmlElement xe1 = xd***eateElement("Users");
    XmlElement xe1Name = xd***eateElement("UserName");
    XmlElement xe1Pass = xd***eateElement("UserPassword");
    xe***me.InnerText = "Jack";
    xe***ss.InnerText = "123";
    xe***t.AppendChild(xe1);
    xe***ppendChild(xe1Name);
    xe***ppendChild(xe1Pass);

    XmlElement xe2 = xd***eateElement("Users");
    XmlElement xe2Name = xd***eateElement("UserName");
    XmlElement xe2Pass = xd***eateElement("UserPassword");
    xe***me.InnerText = "King";
    xe***ss.InnerText = "123";
    xe***t.AppendChild(xe2);
    xe***ppendChild(xe2Name);
    xe***ppendChild(xe2Pass);

    xd.Save(Ap***cation.StartupPath + "Us***.xml">\Us***.xml");
接著在btnOK的click事件中輸入如下代碼﹐作為驗証段﹐當然﹐我并沒有對xml文件中的相關敏感信息加密﹐畢竟只算是一個小的學習總結吧。
    DataSet ds = new DataSet();
    ds***adXml(Ap***cation.StartupPath + "Us***.xml">\Us***.xml");
    //DataView dv = new DataView();
    //dv = ds***bles[0].DefaultView;
    //***Sort = "UserName";
    //***RowFilter = "UserName ='" + Us***ame.Text.Trim() + "'";
    DataTable dt = ds***bles[0];
    DataRow[] dta = dt***lect("UserName='" + Us***ame.Text.Trim() + "'");

    //***s.dataGridView1.DataSource = dv;
    if (dta != null && dt***ength > 0 )
    {
DataRow dr = dta[0];
string strPwd = (string)dr["UserPassword"];
if (strPwd == th***UserPwd.Text.Trim())
{
    Me***geBox.Show("OK");
}
else
{
    Me***geBox.Show("No OK");
}
    }
    else
    {
Me***geBox.Show("No this account");
    }
http://www.cnblogs.com/jinliangliu/archive/2007/01/08/614813.html