473,407 Members | 2,315 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,407 software developers and data experts.

Read Excel data in ASP.NET Error

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";
Conn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;\"";:

and then filling a data set:
cmd1 = new System.Data.OleDb.OleDbCommand("SELECT * FROM ['Test$']", conn1);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd1;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
GridView1.DataSource = objDataset1.Tables[0].DefaultView;
GridView1.DataBind();

but for some reason no numbers show up in the grid or the dataset (I parsed
through it to check the data).

Can anyone suggest what I am doing wrong and/or a better way to do this.

I found some examples that use some Interop classes to read the worksheets,
but I couldn't get those working from ASP.NET...

Thanks for any and all help.

--
John.

http://mscrmguy.blogspot.com/

Apr 27 '07 #1
4 2543


I've had success with these.

//specific column names
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 10
[title_id],[title],[pubdate],[type],[price] FROM [Sheet1$]";

// * from
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 100 * FROM
[Sheet1$]"; //Alternate Version
You can get rid of the "top 10" or "top 100".

I would try a new, blank sheet. Leave it as Sheet1 for the name.

Put in 1 header row.

EmpID,EmpName,HireDate

and fill in about 5 rows or something of data.

and get that to work first. Then move to your more customized sheet/data.

Be VERY anal about your connection string.
Every ; (space) and whatnot matters.


"Johnny" <js********@hotmial.comwrote in message
news:67**********************************@microsof t.com...
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";
Conn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;\"";:

and then filling a data set:
cmd1 = new System.Data.OleDb.OleDbCommand("SELECT * FROM ['Test$']",
conn1);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd1;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
GridView1.DataSource = objDataset1.Tables[0].DefaultView;
GridView1.DataBind();

but for some reason no numbers show up in the grid or the dataset (I
parsed
through it to check the data).

Can anyone suggest what I am doing wrong and/or a better way to do this.

I found some examples that use some Interop classes to read the
worksheets,
but I couldn't get those working from ASP.NET...

Thanks for any and all help.

--
John.

http://mscrmguy.blogspot.com/

Apr 27 '07 #2
On Apr 27, 11:50 am, "sloan" <s...@ipass.netwrote:
I've had success with these.

//specific column names
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 10
[title_id],[title],[pubdate],[type],[price] FROM [Sheet1$]";

// * from
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 100 * FROM
[Sheet1$]"; //Alternate Version

You can get rid of the "top 10" or "top 100".

I would try a new, blank sheet. Leave it as Sheet1 for the name.

Put in 1 header row.

EmpID,EmpName,HireDate

and fill in about 5 rows or something of data.

and get that to work first. Then move to your more customized sheet/data.

Be VERY anal about your connection string.
Every ; (space) and whatnot matters.

"Johnny" <jstraum...@hotmial.comwrote in message

news:67**********************************@microsof t.com...
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";
Conn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;\"";:
and then filling a data set:
cmd1 = new System.Data.OleDb.OleDbCommand("SELECT * FROM ['Test$']",
conn1);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd1;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
GridView1.DataSource = objDataset1.Tables[0].DefaultView;
GridView1.DataBind();
but for some reason no numbers show up in the grid or the dataset (I
parsed
through it to check the data).
Can anyone suggest what I am doing wrong and/or a better way to do this.
I found some examples that use some Interop classes to read the
worksheets,
but I couldn't get those working from ASP.NET...
Thanks for any and all help.
--
John.
http://mscrmguy.blogspot.com/- Hide quoted text -

- Show quoted text -
hi,
I have some code which would work. let me know if u still need the
solution for this. sorry i m 2 lazy to dig into my archieves n post
the code @ this moment.

-
shashank kadge

Apr 27 '07 #3
Hi Guys:

Thanks for the replies. I found out that if the Excel cell had any
formatting applied to it the data was not being read. I am still trying to
find a way around this but for now I am setting all the fields to "test".

--
John.

http://mscrmguy.blogspot.com/

"shashank kadge" <ma**********@gmail.comwrote in message
news:11**********************@n35g2000prd.googlegr oups.com...
On Apr 27, 11:50 am, "sloan" <s...@ipass.netwrote:
>I've had success with these.

//specific column names
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 10
[title_id],[title],[pubdate],[type],[price] FROM [Sheet1$]";

// * from
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 100 * FROM
[Sheet1$]"; //Alternate Version

You can get rid of the "top 10" or "top 100".

I would try a new, blank sheet. Leave it as Sheet1 for the name.

Put in 1 header row.

EmpID,EmpName,HireDate

and fill in about 5 rows or something of data.

and get that to work first. Then move to your more customized
sheet/data.

Be VERY anal about your connection string.
Every ; (space) and whatnot matters.

"Johnny" <jstraum...@hotmial.comwrote in message

news:67**********************************@microso ft.com...
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";
Conn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;\"";:
and then filling a data set:
cmd1 = new System.Data.OleDb.OleDbCommand("SELECT * FROM ['Test$']",
conn1);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd1;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
GridView1.DataSource = objDataset1.Tables[0].DefaultView;
GridView1.DataBind();
but for some reason no numbers show up in the grid or the dataset (I
parsed
through it to check the data).
Can anyone suggest what I am doing wrong and/or a better way to do
this.
I found some examples that use some Interop classes to read the
worksheets,
but I couldn't get those working from ASP.NET...
Thanks for any and all help.
--
John.
>http://mscrmguy.blogspot.com/- Hide quoted text -

- Show quoted text -

hi,
I have some code which would work. let me know if u still need the
solution for this. sorry i m 2 lazy to dig into my archieves n post
the code @ this moment.

-
shashank kadge
Apr 27 '07 #4
Here's another option:

http://www.sqlservercentral.com/colu...ataimports.asp
Convert it all to XML, and pull it out that way.

"Johnny" <js********@hotmial.comwrote in message
news:ur**************@TK2MSFTNGP03.phx.gbl...
Hi Guys:

Thanks for the replies. I found out that if the Excel cell had any
formatting applied to it the data was not being read. I am still trying to
find a way around this but for now I am setting all the fields to "test".

--
John.

http://mscrmguy.blogspot.com/

"shashank kadge" <ma**********@gmail.comwrote in message
news:11**********************@n35g2000prd.googlegr oups.com...
On Apr 27, 11:50 am, "sloan" <s...@ipass.netwrote:
I've had success with these.

//specific column names
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 10
[title_id],[title],[pubdate],[type],[price] FROM [Sheet1$]";

// * from
private readonly string EXCEL_TITLE_SELECT_QUERY = "SELECT top 100 *
FROM
[Sheet1$]"; //Alternate Version

You can get rid of the "top 10" or "top 100".

I would try a new, blank sheet. Leave it as Sheet1 for the name.

Put in 1 header row.

EmpID,EmpName,HireDate

and fill in about 5 rows or something of data.

and get that to work first. Then move to your more customized
sheet/data.

Be VERY anal about your connection string.
Every ; (space) and whatnot matters.

"Johnny" <jstraum...@hotmial.comwrote in message

news:67**********************************@microsof t.com...

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";
Conn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;\"";:

and then filling a data set:
cmd1 = new System.Data.OleDb.OleDbCommand("SELECT * FROM ['Test$']",
conn1);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd1;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
GridView1.DataSource = objDataset1.Tables[0].DefaultView;
GridView1.DataBind();

but for some reason no numbers show up in the grid or the dataset (I
parsed
through it to check the data).

Can anyone suggest what I am doing wrong and/or a better way to do
this.

I found some examples that use some Interop classes to read the
worksheets,
but I couldn't get those working from ASP.NET...

Thanks for any and all help.

--
John.

http://mscrmguy.blogspot.com/- Hide quoted text -

- Show quoted text -
hi,
I have some code which would work. let me know if u still need the
solution for this. sorry i m 2 lazy to dig into my archieves n post
the code @ this moment.

-
shashank kadge

Apr 27 '07 #5

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

Similar topics

3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
0
by: acharyaks | last post by:
Hi life saver, I am using excel component for the development. The purpose is to connect to excel through the odbc connection string. Then through the connection extract data into a dataset and...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
4
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel...
4
by: greg | last post by:
Hi, I have a read only access file with a linked table that connects to a sybase database. So I can still add data to the table even though its read only since the table is really in sybase. ...
6
by: jagguy | last post by:
Hi, i cant read in data from excel 97 using vb.net 2003. I get an exception error . all i want to do is read in values from excel initially. I want to just test it using msgbox. Dim XL...
0
by: suresh_punniyakkodi | last post by:
Hellow Friends, I have one doubt, please help me... In Excel, i have lot of rows and coloumns, i need to read all cell values with in rows and coloumn limit... At the time...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.