read excel file into dataset

G

Guest

Hello,
I am trying to read an excel file, saved in xml format, into a dataset using
the DataSet.ReadXML() method. When I do this 27 seperate tables are created,
each table describes a different portion of the file (ex. doucument
properties, rows, cells, data, print, etc.) All I want to do is load a
DataGrid with the contents of the excel file, so the user would see the same
thing(columns / rows) as if the file where opened in Excel.
Does anyone have any ideas / suggestions on how to do this?

Thanks,
 
B

Balasubramanian Ramanathan

You can oledb datasource to connect to excel sheet

string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
excelPath + ";Extended Properties=Excel 8.0;";

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter("Select * From
[YourSheetName]", connectionString);

DataSet ds = new DataSet();

try
{
connection.Open();

adapter.Fill(ds);

DataGrid1.DataSource = ds.Tables[0];

}


or else you can use the excel objects for more flexible handing.


Its better to use the excel object to read the excel sheets and the load the
data to datatable and bind it to datagrid...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top