473,396 Members | 1,933 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,396 software developers and data experts.

C# ASP example for Excel won't work for us

A couple of use have been trying to figure out why we are not getting
anywhere with this example.

http://support.microsoft.com/default...b;en-us;306572
============
using System.Data.OleDb;
using System.Data;
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"Extended Properties=Excel 8.0;";

// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);

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

// The code to follow uses a SQL SELECT command to display the data from the
worksheet.

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1",
objConn);

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

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

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

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

// Bind data to DataGrid control.
DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();

// Clean up objects.
objConn.Close();
=====

We followed the directions, but when we Start it, the data in the XLS file
does not populate in the DataGrid. Office 2003 and VS2003 on my set. .Net
1.1 loaded (we have not migrated to 2.0 yet.) The ASPX is running on the
local webserver and runs without error.

Does anyone know something obvious that we have not figured into it?
Jun 15 '06 #1
3 1762
Oh, and I fixed this

String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"\"Extended Properties=Excel 8.0;HDR=YES;IMEX=1\"";
"George Ellis" <ge**********@9delta9.com> wrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
A couple of use have been trying to figure out why we are not getting
anywhere with this example.

http://support.microsoft.com/default...b;en-us;306572
============
using System.Data.OleDb;
using System.Data;
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"Extended Properties=Excel 8.0;";

// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);

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

// The code to follow uses a SQL SELECT command to display the data from
the worksheet.

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1",
objConn);

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

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

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

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

// Bind data to DataGrid control.
DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();

// Clean up objects.
objConn.Close();
=====

We followed the directions, but when we Start it, the data in the XLS file
does not populate in the DataGrid. Office 2003 and VS2003 on my set.
.Net 1.1 loaded (we have not migrated to 2.0 yet.) The ASPX is running on
the local webserver and runs without error.

Does anyone know something obvious that we have not figured into it?

Jun 15 '06 #2
Does your Excel worksheet have a named range? Because that's how the example
works.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"George Ellis" wrote:
Oh, and I fixed this

String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"\"Extended Properties=Excel 8.0;HDR=YES;IMEX=1\"";
"George Ellis" <ge**********@9delta9.com> wrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
A couple of use have been trying to figure out why we are not getting
anywhere with this example.

http://support.microsoft.com/default...b;en-us;306572
============
using System.Data.OleDb;
using System.Data;
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"Extended Properties=Excel 8.0;";

// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);

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

// The code to follow uses a SQL SELECT command to display the data from
the worksheet.

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1",
objConn);

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

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

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

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

// Bind data to DataGrid control.
DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();

// Clean up objects.
objConn.Close();
=====

We followed the directions, but when we Start it, the data in the XLS file
does not populate in the DataGrid. Office 2003 and VS2003 on my set.
.Net 1.1 loaded (we have not migrated to 2.0 yet.) The ASPX is running on
the local webserver and runs without error.

Does anyone know something obvious that we have not figured into it?


Jun 15 '06 #3
Yes, it does. The funny thing is that we have a vbscript on another machine
that can do it. The workaround is we may use the script to write a temp
table on the SQL server, redisplay the table and then submit it (the
original goal was to read a XLS and display the contents for a verification
before submitting a job on a server). I just hate doing a write to a table
before the verify of the read. That means creating cleanup logic for an
abort/cancel that we may not be able to catch. Sigh.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:35**********************************@microsof t.com...
Does your Excel worksheet have a named range? Because that's how the
example
works.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"George Ellis" wrote:
Oh, and I fixed this

String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
"\"Extended Properties=Excel 8.0;HDR=YES;IMEX=1\"";
"George Ellis" <ge**********@9delta9.com> wrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
>A couple of use have been trying to figure out why we are not getting
>anywhere with this example.
>
> http://support.microsoft.com/default...b;en-us;306572
> ============
> using System.Data.OleDb;
> using System.Data;
> // Create connection string variable. Modify the "Data Source"
> // parameter as appropriate for your environment.
> String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
> "Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
> "Extended Properties=Excel 8.0;";
>
> // Create connection object by using the preceding connection string.
> OleDbConnection objConn = new OleDbConnection(sConnectionString);
>
> // Open connection with the database.
> objConn.Open();
>
> // The code to follow uses a SQL SELECT command to display the data
> from
> the worksheet.
>
> // Create new OleDbCommand to return data from worksheet.
> OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1",
> objConn);
>
> // Create new OleDbDataAdapter that is used to build a DataSet
> // based on the preceding SQL SELECT statement.
> OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
>
> // Pass the Select command to the adapter.
> objAdapter1.SelectCommand = objCmdSelect;
>
> // Create new DataSet to hold information from the worksheet.
> DataSet objDataset1 = new DataSet();
>
> // Fill the DataSet with the information from the worksheet.
> objAdapter1.Fill(objDataset1, "XLData");
>
> // Bind data to DataGrid control.
> DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
> DataGrid1.DataBind();
>
> // Clean up objects.
> objConn.Close();
> =====
>
> We followed the directions, but when we Start it, the data in the XLS
> file
> does not populate in the DataGrid. Office 2003 and VS2003 on my set.
> .Net 1.1 loaded (we have not migrated to 2.0 yet.) The ASPX is running
> on
> the local webserver and runs without error.
>
> Does anyone know something obvious that we have not figured into it?
>


Jun 15 '06 #4

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

Similar topics

6
by: Geert-Pieter Hof | last post by:
Hello, My VB 6.0 application read and writes data from and to a MS Excel workbook, using the Microsoft.Jet.OLEDB.4.0 provider. Now I want to protect the Excel workbook with a password, but I...
1
by: ST | last post by:
Hi, I'm having problems opening up excel thru my code. It will write and saveas an excel file, but the application won't open on the user's computer, excel seems to be hidden, because it shows up...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
6
by: Jeti [work] | last post by:
I have Office2003 installed, and trying to read excel file from C#. I made ExcelWrapper class, and it worked fine until new version of offide came! Now, when i'm trying to open workbook, i get an...
6
by: Mark | last post by:
I was able to get procedure to work in a VB.Net Windows application, and want to get it to work within a ASP.Net page. It won't create the instance of Excel. It blows up on the CreateObject...
1
by: Dartish | last post by:
Hi all, Thanks in advance for the help I have a DLL that which has several functions that I can call in Excel. I am thinking of how to call these functions in a .net project (authored in C#)....
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
7
by: Eran.Yasso | last post by:
Hi, I have project that automate excel(using Excel COM) which works fine in my home. I took the project from my home to work and tried to build the project but it won't built. I get error "The...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...

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.