03 将MDB文件在DATAGRID中显示

时间:2023-03-08 16:36:05

附件:http://files.cnblogs.com/xe2011/MDB_BindingSource.rar

03 将MDB文件在DATAGRID中显示

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MangerDataBase.mdb";
            string query = "SELECT * FROM ScoreInfo";
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
            OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
            DataTable dTable = new DataTable();
            dAdapter.Fill(dTable);
            BindingSource bSource = new BindingSource();
            bSource.DataSource = dTable;
            dataGridView1.DataSource = bSource;
            dAdapter.Update(dTable);
        }
    }
}

相关文章