PC Review


Reply
Thread Tools Rate Thread

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

 
 
George Ellis
Guest
Posts: n/a
 
      15th Jun 2006
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?


 
Reply With Quote
 
 
 
 
George Ellis
Guest
Posts: n/a
 
      15th Jun 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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?
>



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      15th Jun 2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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?
> >

>
>
>

 
Reply With Quote
 
George Ellis
Guest
Posts: n/a
 
      15th Jun 2006
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]" <(E-Mail Removed)> wrote in message
news:35D644C5-6718-4204-AF5D-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >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?
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
flash object dont work in my excel work sheet Nitn Microsoft Excel Misc 0 4th Jul 2009 08:00 AM
Excel 2000 Simple Shell Command Doesn't Work in Excel 2007 f252863@hotmail.com Microsoft Excel Programming 1 24th Oct 2008 03:06 PM
Excel Work Book Copied Into Word With Paste Special, Excel Workboo MAB Microsoft Excel Misc 0 12th Feb 2008 06:59 PM
HOW TO MAKE A LIST OF WORK SHEET IN WORK BOOK IN EXCEL 2007 goutam Microsoft Excel Programming 1 1st Feb 2008 07:40 AM
HTML Hyperlinks to a specific range work in Excel 2002 but not in Excel 2000 Scott Microsoft Excel Worksheet Functions 0 5th Aug 2003 08:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:24 AM.