블로그 이미지
따시쿵

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2015. 5. 8. 15:48 C#

프로그램 설명


로그인 창에서 메인창으로 이동하는 예제입니다.

이를 위해서 access db를 사용했으며 구조는 이메일, 비밀번호 필드와, idx 자동증가값 필드로 구성되어 있습니다.


테스트를 위해서 데이타는 아래와 같습니다.



실행 후



프로그램 작성


1. access db 에 접근하기 위해서 oledb 를 import 함.

using System.Data.OleDb;

2. [로그인] 버튼에 아래 프로그램을 작성함


        private void btnLogin_Click(object sender, EventArgs e)
        {
            OleDbConnection connect = null;
            OleDbCommand command = null;
            OleDbDataReader reader = null;

            try
            {
                connect = new OleDbConnection();
                connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=../../SampleDB.accdb;Persist Security Info=False";
                connect.Open();

                command = new OleDbCommand();
                command.Connection = connect;
                command.CommandText = "select user_email, user_password from tbl_member where user_email ='" + txtUser_email.Text.Trim()
                                     + "' and user_password = '" + txtUser_password.Text.Trim() + "'";

                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Trace.WriteLine(string.Format("User email : {0}, password : {1}",
                            reader["user_email"].ToString(), reader["user_password"].ToString()));
                    }

                    // 로그인창을 숨기기
                    this.Hide();

                    // 메인폼으로 이동하는 스크립트
                    MainForm f = new MainForm();
                    f.Show();
                    f.WindowState = FormWindowState.Maximized;
                }
                else
                    MessageBox.Show("이메일과 비밀번호를 확인 하시기 바랍니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch { }
            finally
            {
                connect.Close();
            }
        }



소스 파일 : 

Login1.zip

'C#' 카테고리의 다른 글

Event 와 Delegate  (0) 2015.06.01
초단위 시간 경과 보이기  (0) 2015.05.12
멀티플(multiple) 윈도우 - 2  (0) 2015.05.07
데이타베이스 라이브러리  (0) 2015.04.22
BackgroundWorker class  (0) 2015.03.02
posted by 따시쿵