資源簡介
一個實現連接數據庫實現登錄功能的例子,供大家參考一下。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Data.SqlClient;
namespace?LoginDemo
{
????public?partial?class?frmLogin?:?Form
????{
????????///?
????????///?用戶名
????????///?
????????public?static?string?M_str_name;
????????///?
????????///?用戶密碼
????????///?
????????public?static?string?M_str_password;
???????
????????public?frmLogin()
????????{
????????????InitializeComponent();
????????}
????????private?void?btnExit_Click(object?sender?EventArgs?e)
????????{
????????????Application.Exit();
????????}
????????private?void?btnLogin_Click(object?sender?EventArgs?e)
????????{
????????????string?sql?=?“select?*?from?tb_user?where?username=‘“+cmbUserName.Text+“‘?and?userpassword=‘“+txtUserPassword.Text+“‘“;
????????????SqlDataReader?sqlread?=?baseClass.baseOperate.getread(sql);
????????????sqlread.Read();
????????????if?(sqlread.HasRows)
????????????{
????????????????M_str_name?=?cmbUserName.Text;
????????????????M_str_password?=?txtUserPassword.Text;
????????????????frmMain?fmain?=?new?frmMain();
????????????????this.Hide();
????????????????fmain.Show();
????????????}
????????????else
????????????{
????????????????MessageBox.Show(“用戶名或密碼錯誤!““提示“MessageBoxButtons.OKMessageBoxIcon.Information);
????????????????txtUserPassword.Text?=?““;
????????????????cmbUserName.Text?=?““;
????????????????cmbUserName.Focus();
????????????}
????????????sqlread.Close();
?????????
????????}
????????private?void?frmLogin_Load(object?sender?EventArgs?e)
????????{
????????????DataSet?ds?=?new?DataSet();
????????????ds?=?baseClass.baseOperate.getds(“select?*?from?tb_user“);
????????????cmbUserName.DataSource?=?ds.Tables[0];
????????????cmbUserName.DisplayMember?=?“username“;
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-10-29?23:55??login\
?????目錄???????????0??2012-10-29?23:55??login\LoginDemo\
?????文件?????????917??2011-05-07?21:36??login\LoginDemo.sln
?????目錄???????????0??2012-10-29?23:55??login\LoginDemo\ba
?????文件????????2723??2011-05-19?19:16??login\LoginDemo\ba
?????文件????????2000??2011-05-11?21:21??login\LoginDemo\Form1.cs
?????文件????????5846??2011-05-11?21:20??login\LoginDemo\Form1.Designer.cs
?????文件????????7264??2011-05-11?21:20??login\LoginDemo\Form1.resx
?????文件????????1844??2011-05-11?21:48??login\LoginDemo\frmMain.cs
?????文件????????9132??2011-05-11?21:35??login\LoginDemo\frmMain.Designer.cs
?????文件????????5814??2011-05-11?21:35??login\LoginDemo\frmMain.resx
?????文件????????4387??2011-05-07?22:50??login\LoginDemo\LoginDemo.csproj
?????文件?????????493??2011-05-07?21:37??login\LoginDemo\Program.cs
?????目錄???????????0??2012-10-29?23:55??login\LoginDemo\Properties\
?????文件????????1374??2011-05-07?21:36??login\LoginDemo\Properties\AssemblyInfo.cs
?????文件????????3649??2011-05-07?21:41??login\LoginDemo\Properties\Resources.Designer.cs
?????文件????????6737??2011-05-07?21:41??login\LoginDemo\Properties\Resources.resx
?????文件????????1094??2011-05-07?21:36??login\LoginDemo\Properties\Settings.Designer.cs
?????文件?????????249??2011-05-07?21:36??login\LoginDemo\Properties\Settings.settings
?????目錄???????????0??2012-10-29?23:55??login\LoginDemo\Resources\
?????文件?????????269??2011-05-07?21:41??login\LoginDemo\Resources\btnExit.Image.png
?????文件?????????195??2011-05-07?21:41??login\LoginDemo\Resources\btnLogin.Image.png
?????文件???????28588??2011-05-07?21:40??login\LoginDemo\Resources\系統登錄頁面.jpg
評論
共有 條評論