form2.cs

来自「C#编写的」· CS 代码 · 共 68 行

CS
68
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 成绩管理系统_new
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("请输入用户名或密码");
            }
            else
            {
                try
                {
                    string connstr, selectcmd;
                    connstr = "provider=microsoft.jet.oledb.4.0;data source=成绩管理系统.mdb";
                    selectcmd = "select * from 登录信息 where 用户名 = '" + this.textBox1.Text + "' and 密码 = '" + this.textBox2.Text + "'";
                    OleDbConnection conn;
                    OleDbCommand cmd;
                    OleDbDataReader reader;

                    conn = new OleDbConnection(connstr);
                    conn.Open();
                    cmd = new OleDbCommand(selectcmd, conn);
                    reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        From1 newForm1 = new From1();
                        newForm1.Show();
                        this.Hide();
                        //隐藏当前窗体
                    }
                    else
                    {
                        MessageBox.Show("用户名或者密码错误");
                    }

                    reader.Close();
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?