473,569 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=d:\\File one.xls;" +
"Extended Properties=" + (char)34 + "Excel
8.0;HDR=Yes;IME X=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("S ELECT
GroupName, ProtocolID FROM [Sheet1$]", objConn);

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

// Pass the Select command to the adapter.
objAdapter.Sele ctCommand = 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.DataS ource = objDataset.Tabl es[0].DefaultView;
GridView1.DataB ind();
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 12794

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

Similar topics

2
3528
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 cells with data. I have followed this web page's instruction (http://www.haneng.com/Forums_Post.asp?id=4099) to read data out, but whenever the...
1
1802
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 the modified data,it's old data still! I think that maybe caused by c# use a data cache . How to refresh it or how to read the true excel file data?I...
0
4682
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 the Microsoft based files with an OleDbDataAdapter. Then filling the contents of the first worksheet into a dataset. However when I try to add the...
4
6059
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 8.0;HDR=YES;IMEX=1;\""; OleDbConnection conn = new OleDbConnection(connection); try { DataSet ds = new DataSet(); conn.Open();
4
5827
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 support the reading for modification of an Excel-sheet. It allows only the "parse_xls" but I would like to keep the "formatting" in the template.
2
12442
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 tried...and finally i am here.... help me. musa.biralo
1
22171
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 is: some cells in the excel sheet is having two lines value and four lines data, the text file is generating that value in a single line. (Ex. the...
4
2550
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. I am using a connection string: Conn1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="; Conn1 += @"C:\Temp\Success Partners\Test.xls";
3
6232
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook...
3
5378
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.