C Sharp And Ms Access Database Tutorial 6 How To Display Data And Images In Datagridview From Microsoft Access On Form Load
C# And Ms Access Database Tutorial #6 – How To Display Data And Images In Datagridview From Microsoft Access On Form Load
VIDEO TUTORIAL
This Tutorial Shows How To Display Data And Images In Datagridview From Microsoft Access On Form Load In C# Windows Forms Application using visual studio 2010.
C# SOURCE CODE
//Function For Retrieving Data From Microsoft Access Database And Displaying It On DataGridView private void populateDataGridViewFromMicrosoftAccessDatabase() { try { //Clear Datagridview rows before loading data from Microsoft Access Database if (dataGridView1.Rows.Count > 0) { dataGridView1.Rows.Clear(); } OleDbCommand populateDataGridViewFromMicrosoftAccessDatabaseOleDbCommand = new OleDbCommand(selectAllDataFromMicrosoftAccessDatabaseQuery, microsoftAccessDatabaseOleDbConnection); //Open Microsoft Access Database Connection openConnection(); OleDbDataReader reader = populateDataGridViewFromMicrosoftAccessDatabaseOleDbCommand.ExecuteReader(); //Loop through Microsoft Access Database Data while (reader.Read()) { //Add Microsoft Access Database To DataGridView dataGridView1.Rows.Add(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[5].ToString(), reader[6].ToString(), reader[7].ToString(), (byte[])reader[8]); } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //Close Microsoft Access Database Connection closeConnection(); } }
C# SOURCE CODE 2
private void Form1_Load(object sender, EventArgs e) { //Change dataGridView Row Height dataGridView1.RowTemplate.Height = 50; //Populate DataGridView From Microsoft Access Database On Form Load populateDataGridViewFromMicrosoftAccessDatabase(); }