views:

459

answers:

3

hi... i need the code for import excel data to gridview in windows forms application... Plz anyone can tell me that code....

A: 

Try the following code:

Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=" & ExcelFilePath & "; " & _
"Extended Properties=Excel 8.0")

' Select the data from Sheet1 ([in-house$]) of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [in-house$]", MyConnection)

DS = New System.Data.DataSet
MyCommand.Fill(DS)
Dt = DS.Tables(0)
DataGrid1.DataSource = Dt
HotTester
A: 

This is a 4 step process.

I see it as the following:

  1. You need to get your file onto the server.
  2. You need to open the (uploaded?) file.
  3. You need to read the contents of the file, applying any nessesary data parsing.
  4. You need to display the results in a gridview.

This is a simple enough process, its just a matter of breaking it down into logical steps.

Mick Walker
A: 

SpreadsheetGear for .NET comes with an Excel compatible Windows Forms spreadsheet control which supports displaying / editing Excel workbooks and charts with formulas / calculations / formatting intact.

You can learn about the SpreadsheetGear Windows Forms spreadsheet control here and download the free trial here if you want to try it yourself.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson