473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.
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
0 12766

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vanessa | last post by:
I need to read/extract data from an Excel file using ASP. However, the Excel file is not in regular tabular format; instead, it is actually a form. Therefore, it contains many checkbox and merged...
1
by: Napo | last post by:
Hi I use a c# method to open an excel file and to read it's data.But i find a problem that if i changed the excel file data manually by using excelapplication,the readed data by c# method isn't...
0
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
4
by: Hardy Wang | last post by:
Hi all, I have following code to read Excel content into a DataSet string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel...
4
by: Marco Aschwanden | last post by:
Hi I would like to 1. import an existing Excel-sheet (a template) 2. and add some data to it 3. and save it under a different name afterwards. To me it seems, that pyExcelerator does not...
2
by: musa.biralo | last post by:
Hi, i want to read each row of specific column of musa.dbf using macro (VBA) in excel. my main gole is to copy the data of dbf file to excel file. I am new but want to do something..i tried and...
1
by: ashok0866 | last post by:
I had created a macro to read data from an excel sheet and write the values to a text file. I had used "ActiveSheet.Range("GB" & k).Value" command to read the values from the excel. The issue...
4
by: Johnny | last post by:
Hi all: I am trying to write some code to read an Excel spreadsheet from an ASP.NET application. For some reason no fields that have a number in them are read, while text data is read just fine....
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.