Over the past two days, I have made some interesting experiences in xml data production. I have also made some comments and noted them here. It is a small result of learning xml. The technical expertise content is not very good, so experts do not need to read it. Haha .... over the past two days, I have made some interesting experiences in xml data production. I have also made some comments and noted them here. It is a small result of learning xml. The technical expertise content is not very good, so experts do not need to read it. Haha ....
If we don't talk much about it, our programmers pay the most attention to the actual use. below we will generate xml data for ourselves, and then share the entire process in our workshop..
First, create a windows disaster case and drag two TextBox from the toolbox. The ID is different from UserName and UserPwd, then drag the two buttons to exit. The ID is btnOK and btnGen. text encryption is divided into "plain Text" and "created ".
Then add the following generation to the btnGen click event to generate an xml file as a data volume ﹕
XmlDocument xd = new XmlDocument(); XmlNode xnDec = xd.CreateNode(XmlNodeType.XmlDeclaration, "", ""); XmlElement xeRoot = xd.CreateElement("Users"); xd.AppendChild(xnDec); xd.AppendChild(xeRoot); XmlElement xe1 = xd.CreateElement("Users"); XmlElement xe1Name = xd.CreateElement("UserName"); XmlElement xe1Pass = xd.CreateElement("UserPassword"); xe1Name.InnerText = "Jack"; xe1Pass.InnerText = "123"; xeRoot.AppendChild(xe1); xe1.AppendChild(xe1Name); xe1.AppendChild(xe1Pass); XmlElement xe2 = xd.CreateElement("Users"); XmlElement xe2Name = xd.CreateElement("UserName"); XmlElement xe2Pass = xd.CreateElement("UserPassword"); xe2Name.InnerText = "King"; xe2Pass.InnerText = "123"; xeRoot.AppendChild(xe2); xe2.AppendChild(xe2Name); xe2.AppendChild(xe2Pass); xd.Save(Application.StartupPath + "\\Users.xml");
Then, in the click event of btnOK, inject the following code as the sequence segment. of course, I didn't encrypt the sensitive information in the xml file. summary of a small learning environment.
DataSet ds = new DataSet(); ds.ReadXml(Application.StartupPath + "\\Users.xml"); //DataView dv = new DataView(); //dv = ds.Tables[0].DefaultView; //dv.Sort = "UserName"; //dv.RowFilter = "UserName ='" + UserName.Text.Trim() + "'"; DataTable dt = ds.Tables[0]; DataRow[] dta = dt.Select("UserName='" + UserName.Text.Trim() + "'"); //this.dataGridView1.DataSource = dv; if (dta != null && dta.Length > 0 ) { DataRow dr = dta[0]; string strPwd = (string)dr["UserPassword"]; if (strPwd == this.UserPwd.Text.Trim()) { MessageBox.Show("OK"); } else { MessageBox.Show("No OK"); } } else { MessageBox.Show("No this account"); }
The above is the content for implementing an xml database login verification from scratch. For more information, see PHP Chinese network (www.php1.cn )!