How to View Data from MS Access in Data Grid View?
29,001
Refer following code:
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;
Hope its helpful.
Author by
Taha Kirmani
Updated on June 21, 2020Comments
-
Taha Kirmani about 4 years
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;