标题:通过datagridview显示access数据库中内容(附代码)
取消只看楼主
gfayj
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2009-8-3
结帖率:0
已结贴  问题点数:20 回复次数:1 
通过datagridview显示access数据库中内容(附代码)
private void button1_Click(object sender, EventArgs e)
        {
            try
            {    // 利用 OleDbConnectionStringBuilder 对象来构建
                // 连接字符串。
                OleDbConnectionStringBuilder connectStringBuilder = new OleDbConnectionStringBuilder();
                connectStringBuilder.DataSource = @"D:\temp\db1.mdb";
                connectStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
                using (OleDbConnection cn = new OleDbConnection(connectStringBuilder.ConnectionString))
                {
                    DataSet ds = new DataSet();
                    OleDbCommand cmdLiming = new OleDbCommand("SELECT * FROM cade", cn);
                    cn.Open();
                    using (OleDbDataReader drLiming = cmdLiming.ExecuteReader())
                    {
                        ds.Load(drLiming, LoadOption.OverwriteChanges, new string[] { "cade" });
                        // 将 BindingSource 组件绑定到 DataSet 当中的"cade"数据表。
                        this.BindingSource1.DataSource = ds.Tables["cade"];
                        // 将 DataGridView 控件绑定到 BindingSource 组件。
                       this.DataGridView1.DataSource = this.BindingSource1;
                    }
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

        }
大家帮我看看问题出在哪?谢谢
搜索更多相关主题的帖子: 数据库 datagridview access 代码 
2009-08-04 16:00
gfayj
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2009-8-3
得分:0 
回复 2楼 jedypjd
出现的3个错误,我通过重新定义后已经改对了,但运行后通过点击button却无法显示表中的数据,不知道是怎么回事?
2009-08-04 19:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-281545-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.238424 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved