470,871 Members | 2,317 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,871 developers. It's quick & easy.

Read Excel Data Using ASP.net 2.0 C#

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.

// 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;
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
0 12612

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hardy Wang | last post: by
2 posts views Thread by musa.biralo | last post: by
4 posts views Thread by Johnny | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.