title: Charting in vb.net form using excel data source
body: <p>I have a form in which there is a button &amp; chart object. I have an excel sheet which I am populating dynamically. Columns C &amp; D have headers "EOS" &amp; "Count" in cells C1 &amp; D1 respectively. The data filling starts C2 &amp; D2 onwards till variable number of rows.</p>
  
  <p>What I want is, when the button n form is clicked, a simple bar chart is displayed in the cart area. the chart should have X-axis as C2, C3, ....,Cn values and Y-axis as D2, D3, ....,Dn values. I have the following code from this <a href="http://www.siddharthrout.com/2011/10/18/charting-with-vb-net-2010/" rel="nofollow">page</a> that does what I need but uses an Access db as source. </p>
  
  <p>Can anyone please show me how to achieve it using <code>excel sheet</code> as data source? </p>
  
  <pre><code>'~~&gt; Code to generate the chart
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
  e As System.EventArgs) Handles Button2.Click
      Dim strConn As String = _
      "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; TextBox1.Text &amp; _
      ";Persist Security Info=False;"
  
      Dim tblFields As String = "SELECT * from Table1"
  
      Dim conn As New OleDbConnection(strConn)
      Dim oCmd As New OleDbCommand(tblFields, conn)
      Dim oData As New OleDbDataAdapter(tblFields, conn)
      Dim ds As New DataSet
  
      conn.Open()
      oData.Fill(ds, "Table1")
      conn.Close()
  
      Chart1.DataSource = ds.Tables("Table1")
      Dim Series1 As Series = Chart1.Series("Series1")
      Series1.Name = "Sales"
      Chart1.Series(Series1.Name).XValueMember = "nFruits"
      Chart1.Series(Series1.Name).YValueMembers = "nSales"
  
      Chart1.Size = New System.Drawing.Size(780, 350)
  End Sub
  </code></pre>