Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Query Table and SQL Server

Hi All,

I am trying to populate a spreadsheet from SQL Server by creating a qyery
table and using a select statement in C# using Excel 11. My code looks like
this:

string sConn = @"Provider=SQLOLEDB.1;Password=pwd;Persist Security
Into=True;User ID=sa;Initial Catalog=DB1;Data Source=Server1";
ADODB.ConnectionClass oConn = new ADODB.ConnectionClass();
oConn.ConnectionString = sConn;

string sQuery = "SELECT * from MyTable";
Excel.Range oRange = oSheet.get_Range("A1",oMissing);

Excel.QueryTables oQryTbls = oSheet.QueryTables;
// I have tried
// Excel.QueryTable oQryTbl = oSheet.QueryTables.Add(oConn, oRange,sQuery);
// also

Excel.QueryTable oQryTbl = oQryTbls.Add(sConn, oRange,sQuery);
// I have tried
// Excel.QueryTable oQryTbl = oQryTbls.Add(oConn, oRange,sQuery);
// also
oQryTbl.RefreshStyle = Excel.XlCellInsertionMode.xlInsertEntireRows;
oQryTbl.Refresh(false);


I get an unhandled exception of type
System.Runtime.InteropServices.COMException in mscorlib.dll
The HRESULT value is 0x800A03EC.

Can anyone point me in the right direction ?

TIA
Peter
Reply
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
Query SQL Server from Excel Doctorjones_md Excel Worksheet Functions 1 January 6th 07 08:35 AM
Query from ms sql server question canix[_2_] Excel Programming 2 August 10th 05 06:47 PM
Pivot Table based on SQL Server query Ben Rum Excel Programming 3 March 31st 05 11:55 AM
Query SQL Server Kevin L Excel Programming 1 November 30th 04 09:11 PM


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

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

About Us

"It's about Microsoft Excel"