0 Replies - 12227 Views - Last Post: 03 February 2009 - 09:59 AM Rate Topic: -----

#1 wnewcomb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-August 08

import excel data into datagridview using vb

Posted 03 February 2009 - 09:59 AM

		connect = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & "data source=" & BookToWorkOn & ";Extended Properties=Excel 8.0;")

		connect.Open()

		' Puts the ingredient column from Named Range [Ingredient} in

		adapter = New System.Data.OleDb.OleDbDataAdapter("select * From [Ingredient]", connect)
		adapter.Fill(dataset)

		Me.DataGridView1.DataSource = dataset.Tables(0)

		connect.Close()
	  
		

  

		'Adds the column data from the Named Range [Found] in

		adapter = New System.Data.OleDb.OleDbDataAdapter("select * from [Found]", connect)

		adapter.Fill(dataset)


		Me.DataGridView2.DataSource = dataset.Tables(0)

		connect.Close()
		dataset.Clear()


In the above code I am trying to import two excel named ranges (columns) into a datagridview control so that they display in two columns. when I execute the code the first the colmn names are displayed properly and the first range row data displays properly in the first column but the row data in the second column displays in rows below the used rows in the first column. I need the row data from each column to be displayed side by side

Is This A Good Question/Topic? 0
  • +

Page 1 of 1