如何在数据网格视图中从MS Access查看数据? [英] How to View Data from MS Access in Data Grid View?

查看:83
本文介绍了如何在数据网格视图中从MS Access查看数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C-Sharp的新手,我正尝试从C-Sharp访问我的数据库,我编写了以下代码,而我不知道接下来要写什么来查看数据。我已经在网上搜索了此内容,但并没有得到太多。

I am new in C-Sharp, i am trying to access my Database from C-Sharp, i have written the following code, and i dont know what to write next to view data. I have searched this on net but didnt get much. Kindly tell me this in easy code.

string connection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Database3.accdb";

OleDbConnection conn = new OleDbConnection(connection);
conn.Open();
OleDbCommand cmd = new OleDbCommand("Select * from score", conn);

OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.SelectCommand = cmd;


推荐答案

请参阅以下代码:

string strProvider = "@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Database3.accdb";
string strSql = "Select * from score";
OleDbConnection con = new OleDbConnection(strProvider);
OleDbCommand cmd = new OleDbCommand(strSql, con);
con.Open();
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable scores = new DataTable();
da.Fill(scores);
dataGridView1.DataSource = scores;

希望它会有所帮助。

这篇关于如何在数据网格视图中从MS Access查看数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆