namespace a
{
    public partial class Form2 : Form
    {
        private DataTable dt = new DataTable();
        private OleDbDataAdapter oda = new OleDbDataAdapter();
        private Boolean isUpdate = false;        public Form2()
        {
            InitializeComponent();
        }        private void Form2_Load(object sender, EventArgs e)
        {
            string strConnection; 
            strConnection = "Provider=Microsoft.Jet.OleDb.4.0;User Id=Admin;Jet OLEDB:Database Password=1978;Persist Security Info=False;";
            strConnection += "Data Source=.\\print.mdb";
            OleDbConnection conn = new OleDbConnection(strConnection);
            //conn.Open();        
            OleDbCommand ocd = new OleDbCommand("select * from printset",conn);
            oda.SelectCommand = ocd;
            oda.Fill(dt);
            dataGridView1.DataSource = dt;
            dataGridView1.Columns[0].ReadOnly = true;
            dataGridView1.Columns[1].ReadOnly = true;
            dataGridView1.AllowUserToResizeRows = false;
            dataGridView1.AllowUserToAddRows = false;
            //conn.Close();        }        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (this.dataGridView1.Rows.Count != 0)
            {
                for (int i = 0; i < this.dataGridView1.Rows.Count; )
                {
                    this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.MistyRose;
                    i += 2;
                }
            }         }        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (isUpdate==true)
            {
                try
                {
                    OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
                    oda.Update(dt);
                    isUpdate = false;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
                MessageBox.Show("更新成功! ");
            }
            else
            {
                MessageBox.Show("没有更新内容! ");
            }           
        }         
    }
}