By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Read Excel Data Using ASP.net 2.0 C#

P: n/a
Hi All,

I try to read the data from the excel, but I ran into this problem

I have two excel files.
file one.xls data inside like this:

1234 1234
1234 1234
abc-123 abc-123
abc-123 abc-123
File two.xls data inside like this:
abc-123 abc-123
abc-123 abc-123
1234 1234
1234 1234
Read from file one:

source = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=d:\\Fileone.xls;" +
"Extended Properties=" + (char)34 + "Excel
8.0;HDR=Yes;IMEX=1;" + (char)34;

/*
OleDbConnection objConn = new OleDbConnection(source);

// Open connection with the database.
objConn.Open();

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT
GroupName, ProtocolID FROM [Sheet1$]", objConn);

// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter = new OleDbDataAdapter();

// Pass the Select command to the adapter.
objAdapter.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.
DataSet objDataset = new DataSet();

// Fill the DataSet with the information from the worksheet.
objAdapter.Fill(objDataset, "XLData");

GridView1.DataSource = objDataset.Tables[0].DefaultView;
GridView1.DataBind();
Gridview only display:
1234 1234
1234 1234

If I read from file two:
Gridview only display:
abc-123 abc-123
abc-123 abc-123
1234 1234
1234 1234
Both column in the excel is general.

Please help. Thanks in advance

May 23 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.