How to Override DataGridView

The DataGridView is used to display the contents of a DataTable in a DataSet. You can use it to help you display multiple records from a database on your website. You can bind your DataGridView to records, which will then display new data on your site. If you want to override your DataGridView control, you can do so with databinding and adding new records to display.

Instructions

    • 1

      Locate and double-click the SLN file to launch your DataGridView.

    • 2

      Type the following code to access your database:

      string con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\myDatabase.mdb";

      string query = "SELECT * FROM customers";

      OleDbDataAdapter adapter = new OleDbDataAdapter(query, con);

      OleDbCommandBuilder build = new OleDbCommandBuilder(adapter);

      Replace "myDatabase" with your database name.

    • 3

      Enter the following script to override your DataGridView:

      DataGridView dv = new DataGridView();

      BindingSource binding = new BindingSource();

      binding.DataSource = table;

      dv.DataSource = binding;

    • 4

      Click "Save," "Run" to apply and execute your settings.

Related Searches:

References

Comments

Related Ads

Featured