DataGridView DataSource C# Source Code

How to fill DataGridView items on c# if we’re connect using OleDbConnection?

We’re gonna use DataSet for filling the DataGridView.. Here’is the example…

The information about variables and objects used is

  1. dataGridView1 –> DataGridView GUI Object from Toolbox
  2. Program.con –> OleDbConnection (using System.Data.OleDb)
  3. combo_produk_id –> ComboBox GUI Object from Toolbox
        private void Item_Load(object sender, EventArgs e)
            dataGridView1.DataSource = null;
            DataSet ds = new DataSet();

            OleDbCommand cmd = Program.con.CreateCommand();
            cmd.CommandText = "SELECT * FROM produk";

            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())


            OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
            dataGridView1.DataSource = ds.Tables[0];

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation