這兩天﹐對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"); //***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
上一篇: 使用xml作为数据源,配合asp:Menu类自由扩展菜单项
下一篇: XML 增、删、改和查示例