title: Binding an EXCEL worksheet to a dataGridView?
body: <p>I am trying to bind an EXCEL datasheet to a <strong>dataGridView</strong>? I think that this is close but I do not know why the data is not showing up in the grid. I have seen several post on Stackoverflow but I could not get any of them to work. So I decided to put my own example up and see if I can get someone to try this code. All the form needs is a button with the click event and the dataGridView.     </p>
  
  <p><strong>Class Code:</strong></p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.Net.Mail;
      using System.Data.OleDb;
  
      namespace TestExcel
      {
          public partial class Form1 : Form
          {
              public Form1()
              {
                  InitializeComponent();
              }
  
              private void button1_Click(object sender, EventArgs e)
              {
                  String name = "Items";
                  String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                                  @"C:\Users\itpr13266\Desktop\test.xls" + 
                                  ";Extended Properties='Excel 8.0;HDR=YES;';";
  
                  OleDbConnection con = new OleDbConnection(constr);
                  OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
                  con.Open();
  
                  OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
                  DataTable data = new DataTable();
                  sda.Fill(data);
                  dataGridView1.DataSource = data;
              }
          }
      }
  </code></pre>