주간 베스트 월간 베스트 3개월 베스트 베스트 게시물
꽃배달 한국, 중국 전지역배송

c#登录窗口代码

deam | 2011.01.06 20:15:17 댓글: 0 조회: 4103 추천: 0
분류웹 프로그래밍 https://life.moyiza.kr/itstudy/1760249

public partial class frmLogin : Form
{
    //声明变量
    OleDbConnection conObj;
    OleDbCommand cmdObj;
    OleDbDataReader readObj;
    string sql;

    //窗体的构造方法
    public frmLogin()
    {
        InitializeComponent();
    }

    //窗体的 Load 事件
    private void frmLogin_Load(object sender, EventArgs e)
    {
        conObj = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=txl.mdb");
        conObj.Open();
    }

    //自定义方法
    private bool Allfill()
    {
        if (txtId.Text == "") return false;
        if (txtPass.Text == "") return false;
        return true;
    }    


    //登录
    private void button1_Click(object sender, EventArgs e)
    {
        if (Allfill())
        {
            sql = "SELECT * FROM MngInfo WHERE "
                + "Id ='" + txtId.Text + "'";
            cmdObj = new OleDbCommand(sql, conObj);
            readObj = cmdObj.ExecuteReader();
            if (readObj.HasRows)
            {
                readObj.Read();
                if (readObj.GetString(1) == txtPass.Text)
                {                     
                    frmMain fMain = new frmMain(this);
                    fMain.ShowDialog();
                }
                else
                {
                    MessageBox.Show("密码出错!");
                }

            }
            else
            {
                MessageBox.Show("用户不存在!");
            }
        }
        else
        {
            MessageBox.Show("字段不能为空");
        }
    }

    //退出
    private void button2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }
}
上学时候班主任写的代码~虽然简单但是很有用哦~学习c#的朋友可以参考参考

추천 (0) 선물 (0명)
IP: ♡.67.♡.133
3,006 개의 글이 있습니다.
제목 글쓴이 날짜 조회
관리자
2003-09-20
11774
관리자
2003-09-20
11317
관리자
2003-09-20
20390
지구인
2010-08-27
19255
지구인
2009-09-07
13553
SOLIDH
2010-01-29
15525
엔죠라이프
2004-10-07
16634
세뇨리타
2011-01-22
4190
세뇨리타
2011-01-22
6919
세뇨리타
2011-01-07
3880
세뇨리타
2011-01-07
3222
deam
2011-01-06
4103
세뇨리타
2011-01-05
4962
deam
2011-01-04
3160
방울이엄마
2010-12-30
3506
사막모우스
2010-12-20
3964
풍이
2010-12-07
3890
세뇨리타
2010-11-23
6244
세뇨리타
2010-11-23
4695
세뇨리타
2010-11-23
5138
세뇨리타
2010-11-23
5053
세뇨리타
2010-11-23
4513
세뇨리타
2010-11-20
5251
세뇨리타
2010-11-20
4214
세뇨리타
2010-11-20
3836
세뇨리타
2010-11-20
3892
세뇨리타
2010-11-20
2956
세뇨리타
2010-11-18
3046
모이자 모바일