Video Series: Display MS Access Database Records in C# DataGridView

The best way to view data from a database table is to display it in the form of a table. This tutorial will teach you exactly how to get records from Microsoft Access Database and display it in DataGridView control.

English

[blip.tv http://blip.tv/play/AYOJmmAA?p=1 width=”550″ height=”443″]

Urdu

[blip.tv http://blip.tv/play/AYOJr2MA?p=1 width=”550″ height=”443″]
Advertisements

One thought on “Video Series: Display MS Access Database Records in C# DataGridView

  1. AOA
    Sir i tried you code it is running file with the first two values the rest are not shown in Data Grid

    OleDbConnection con = new OleDbConnection();
    con.ConnectionString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source= ..\\empdatabase.accdb”;
    con.Open();

    OleDbCommand vsql = new OleDbCommand();
    vsql.Connection = con;
    vsql.CommandText = ” Select * from Emp_Info”;

    OleDbDataReader reader = vsql.ExecuteReader();

    while (reader.Read())
    {
    dataGridView1.Rows.Add();

    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“emp_id”].Value = reader[0].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“emp_fname”].Value = reader[1].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“emp_lname”].Value = reader[2].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“DOB”].Value = reader[3].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Passport”].Value = reader[4].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Visit Visa”].Value = reader[5].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Gender”].Value = reader[6].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Mobile”].Value = reader[7].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Nationality”].Value = reader[8].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“First Name”].Value = reader[9].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Home Phone”].Value = reader[10].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Emirates id”].Value = reader[11].ToString();
    dataGridView1.Rows[dataGridView1.Rows.Count-1].Cells[“Picture”].Value = reader[11].ToString();

    }
    con.Close();

    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s