登陆界面

C#开发身份证信息管理系统之登陆
代码的实现:

最上面using添加:
using System.Data.OleDb;

namespace IDmsg
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        OleDbConnection oleDb = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = msg.mdb");//连接数据库语句

登陆button中的事件:

try				//用try捕获连接数据库可能出现的错误
            {
                if (User.Text.Trim() == "" || Passwd.Text.Trim() == "")
                {
                    MessageBox.Show("请输入账号密码!", "Warning!");
                }
                else
                {
                    oleDb.Open();
                    string sql = "select * from Users where user='" + User.Text.Trim() + "' and passwd='" + Passwd.Text.Trim() + "'";					//查询数据库该账号密码是否存在
                    OleDbCommand comm = new OleDbCommand(sql, oleDb);
                    if (1 != comm.ExecuteNonQuery())
                    {
                        Main m1=new Main();
                        this.Hide();
                        m1.toolStripStatusLabel4.Text = User.Text.Trim();
                        m1.Show();
                    }
                    oleDb.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);   //打印错误信息
                oleDb.Close();
            }


取消button中的事件:
Application.Exit();

相关文章:

  • 2021-04-12
  • 2022-12-23
  • 2021-12-03
  • 2021-12-31
  • 2021-11-06
  • 2021-08-23
  • 2022-12-23
猜你喜欢
  • 2021-09-21
  • 2021-05-25
  • 2021-05-09
  • 2021-06-08
  • 2022-12-23
相关资源
相似解决方案