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.OleDb;

namespace Ex04_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("用户名或密码不能为空！");
            }
            else
            {
                try
                {
                    string strPath = Application.StartupPath + "\\Mydata.accdb";

                    string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0; Jet OLEDB:DataBase Password='" + this.textBox2.Text + "';User Id='" + this.textBox1.Text + "';Data source=" + strPath;
                    OleDbConnection oleCon = new OleDbConnection(ConStr);
                    OleDbDataAdapter oleDap = new OleDbDataAdapter("select * from 员工信息", oleCon);
                    DataSet ds = new DataSet();
                    oleDap.Fill(ds, "员工信息");
                    this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
                    oleCon.Close();
                    oleCon.Dispose();
                }
                catch (Exception ey)
                {
                    MessageBox.Show(ey.Message);
                }
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
