LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Querying Excel document with OleDb

Hi!

I have a puzzling situation here. I have an application that loads an
Excel document and subsequently queries the document for information
using OleDb. Code snippet below:

OleDbConnection conn = null;
DataSet dataSet = null;
OleDbCommand cmd = null;
OleDbDataAdapter adapter = null;
string sFileName = "test.xls";

try
{
// Get the data out of the spreadsheet into a dataset. Try opening the
Excel file with ADO
string sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
sConnect += sFileName + ";Extended Properties=Excel 8.0;";

conn = new OleDbConnection(sConnect);
conn.Open();

// Querying an insane amount of cells...
string sSQL = "Select * from [" + sWorksheetName + "$A1:IV65536]";
cmd = new OleDbCommand(sSQL, conn);
adapter = new OleDbDataAdapter();
adapter.SelectCommand = cmd;
dataSet = new DataSet();

adapter.Fill(dataSet, sWorksheetName);
}
finally
{
if(null != conn)
{
if(ConnectionState.Open == conn.State)
conn.Close();
conn.Dispose();
conn = null;
}
}

Everything works as I assume it should. There's something strange
though, that I can't quite figure out.

Let's say I have the document open in Excel at the time this code is
executed. If I make changes to the document in Excel (but DO NOT save
it!) the query in the code actually picks up the changes! If I then
quit Excel and don't save the changes, then the code picks up the
original values. This seems very strange, as I have never saved the
document to disk, and I don't see why connecting to it in this manner
would return me that data.

Any ideas? I'm using C# / .NET 1.1, and Excel 2003 SP2.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection to Excel from .Net using Oledb c23chaos Excel Programming 0 March 8th 06 03:50 PM
Using OleDB to get data from Excel dvd00 Excel Discussion (Misc queries) 1 November 30th 04 04:32 PM
OLEDB Help Excel 2002 Brian Belger Excel Programming 1 September 28th 04 08:56 AM
EXCEL AND OLEDB Yama Excel Programming 4 February 25th 04 03:29 PM
Excel schema using Jet OLEDB Provider? mike Excel Programming 1 December 22nd 03 09:25 AM


All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"