[英]how can i check if the textbox.text is equal to my first line file.xml
我想知道如何檢查用戶類型的textbox1.text是否等於我的login.xml文件第一行的文本,以及if第二個textbox.text是否等於我的登錄的第二行.xml文件,如果是,他可以登錄,如果沒有顯示messabox說passwor或用戶名不正確。 我會貶低那個。
順便說一句,這是login.xml文件中的內容
<?xml version="1.0" encoding="UTF-8"?>
<informacao xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Data1>master</Data1> //this is the first line i want to make this the username
<Data2>master</Data2> //this is the second line i want to make this the password
</informacao>
您可以使用Linq to Xml從xml文件中讀取值:
var xdoc = XDocument.Load("login.xml"); // load xml file into document
var userName = (string)xdoc.Root.Element("Data1"); // get value of Data1 element
var password = (string)xdoc.Root.Element("Data2");
if (textbox1.Text != userName || textbox2.Text != password)
{
MessageBox.Show("Username and/or password is invalid");
return;
}
注意:對xml元素和UI控件使用更好的命名。 將用戶憑證存儲在xml文件中也不是一個好主意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.