i want to show all the records which are in ms access database,but it displays only one record…
I have the following code
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\mayur patil\\My Documents\\Dairy_db\\tblCompany.mdb";
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
string sql = "SELECT * From tblCompany";
da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
da.Fill(ds);
DataRow dr = ds.Tables[0].Rows[0];
int cnt = ds.Tables[0].Rows.Count;
textBox1.Text = cnt.ToString();
for (int i = 0; i < cnt; i++)
{
dataGridView1.Rows[i].Cells[0].Value = dr.ItemArray.GetValue(1).ToString();
dataGridView1.Rows[i].Cells[1].Value = dr.ItemArray.GetValue(2).ToString();
}
}
how can i display all the records from the ms access database,in my DataGridView?
1 Answer