首先要把Label1的屬性Visible設(shè)置為false,然后雙擊button1輸入:
創(chuàng)新互聯(lián)成立于2013年,我們提供高端重慶網(wǎng)站建設(shè)公司、成都網(wǎng)站制作、網(wǎng)站設(shè)計、網(wǎng)站定制、營銷型網(wǎng)站建設(shè)、微信平臺小程序開發(fā)、微信公眾號開發(fā)、營銷推廣服務(wù),提供專業(yè)營銷思路、內(nèi)容策劃、視覺設(shè)計、程序開發(fā)來完成項目落地,為成都玻璃鋼坐凳企業(yè)提供源源不斷的流量和訂單咨詢。
Dim rs As New Data.DataView()
Dim rs As New DataView()
conn.DataFile = "users.mdb"
conn.SelectCommand = "select top 1 * from users where name='" txtUserName.Text "'and pass='" txtPassword.Text "'"
rs = conn.Select(DataSourceSelectArguments.Empty)
if rs.Count Then
Label1.Visible=true
Session("name") = Trim(txtUserName.Text)
Session("pass") = Trim( txtPassword.Text)
MsgBox("登錄成功", MsgBoxStyle.SystemModal)
Response.Redirect("")
Else
MsgBox("對不起!用戶名和密碼不正確,請重新輸入。", MsgBoxStyle.SystemModal)
End If
代碼如下:
/// summary
/// 連接到窗體:通過密碼保護信息找回密碼!
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void lbl_mibao_Click(object sender, EventArgs e)
{
Getbackpwd getbackpwd = new Getbackpwd();
getbackpwd.Show();
}
/// summary
/// 當(dāng)該窗體加載時從xml文件中讀取用戶信息并加載到combox的Items中
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void Addresslist_Load(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
while (reader.Read())
{
//if (reader.LocalName.Equals("Name") || reader.LocalName.Equals("Number"))
if (reader.LocalName.Equals("username"))
{
this.cmbUserName.Items.Add(reader.ReadString());
}
//if (reader.LocalName.Equals("Number"))
//{
// this.label2.Text += reader.ReadString() + "\n";\
//}
}
reader.Close();
}
/// summary
/// 保存用戶名到user.xml
/// /summary
//在listcontol上更改SelectedValue時執(zhí)行從數(shù)據(jù)庫讀取密碼的事件
private void cmbUserName_SelectedValueChanged(object sender, EventArgs e)
{
string username = cmbUserName.Text.Trim();
string sql = string.Format("select pwd from Admin where Username='{0}'", username);
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
txtpwd.Text = (string)dataReader["pwd"];
checkBoxpwd.Checked = true;
}
}
catch
{
MessageBox.Show("數(shù)據(jù)庫操作出錯!");
}
finally
{
DBHelper.connection.Close();
}
}
/// summary
/// 記住密碼操作
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void checkBoxpwd_Enter(object sender, EventArgs e)
{
bool check = true;
check = checkinput(cmbUserName.Text.Trim());
if ((string)cmbUserName.Text.Trim() == "")
{
MessageBox.Show("請輸入用戶名", "輸入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbUserName.Focus();
}
else
{
if (txtpwd.Text.Trim() == "")
{
MessageBox.Show("請輸入密碼", "輸入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtpwd.Focus();
}
else
{
bool isValidUser = false; // 標(biāo)識是否為合法用戶
string message = ""; // 如果登錄失敗,顯示的消息提示
// 如果驗證通過,就顯示相應(yīng)的用戶窗體,并將當(dāng)前窗體設(shè)為不可見
if (ValidateInput())
{
// 調(diào)用用戶驗證方法
isValidUser = ValidateUser(cmbUserName.Text, txtpwd.Text, ref message);
// 如果是合法用戶,顯示相應(yīng)的窗體
if (isValidUser)
{
if (check == true)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");//(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
XmlElement node = doc.CreateElement("user");
XmlNode xnode = (XmlNode)doc.CreateElement("username");
xnode.InnerText = cmbUserName.Text.Trim();
node.AppendChild(xnode);
doc.DocumentElement.InsertAfter(node, doc.DocumentElement.LastChild);
doc.Save(@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
//doc.Load (@"E:\面向?qū)ο?-C#練習(xí)\通訊錄\address list\address list\user.xml");
}
}
// 如果登錄失敗,顯示相應(yīng)的消息
else
{
MessageBox.Show(message, "記住密碼失敗!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
/// summary
/// 驗證當(dāng)前combox中內(nèi)容是否已經(jīng)存在于xml文件中
/// /summary
/// param name="text"/param
/// returns/returns
private bool checkinput(string text)
{
int count;
bool c = true;
for (count = 0; count cmbUserName.Items.Count;count ++ )
{
if (text ==(string )cmbUserName .Items [count])
{
c=false;
}
}
return c;
}
xml文件內(nèi)容如下:?xml version="1.0" encoding="utf-8"?
person
user
Private?Sub?BtOk_Click(ByVal?sender?As?Object,?ByVal?e?As?System.EventArgs)?Handles?Btok.Click
Dim?con?As?OleDbConnection?=?New?OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data?Source=Admin.accdb;Persist?Security?Info=True")
Dim?com?As?OleDbCommand?=?New?OleDbCommand("select?*?from?用戶名",?con)
con.Open()
Dim?h1?As?OleDbDataReader
Dim?table?As?New?DataTable
h1?=?com.ExecuteReader()
table.Load(h1)
If?txtName.Text?=?""?Then
MsgBox("請輸入用戶名",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯誤提示")
ElseIf?txtName.Text??""?And?txtPasswd.Text?=?""?Then
MsgBox("請輸入密碼",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯誤提示")
ElseIf?table.Select("用戶名='"??txtName.Text??"'").Length??0?Then
If?table.Select("用戶名='"??txtName.Text??"'")(0)("密碼").ToString?=?txtPasswd.Text?Then
MsgBox("成功登陸",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯誤提示")?Then
Form1.Show()
Me.Visible?=?False
Exit?Sub
Else
MsgBox("密碼錯誤",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯誤提示")
End?If
Else
MsgBox("用戶名不存在",?MsgBoxStyle.OkCancel?+?MsgBoxStyle.Exclamation,?"錯誤提示")
Exit?Sub
End?If
table.Clear()
h1.Close()
con.Close()
End?Sub
標(biāo)題名稱:vbnet登錄,vb net
網(wǎng)站URL:http://chinadenli.net/article16/dsicegg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)頁設(shè)計公司、外貿(mào)網(wǎng)站建設(shè)、微信公眾號、品牌網(wǎng)站建設(shè)、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)