Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

C# and Excel QueryTable Problem
Hi ,



Can you provide some sample of querytable in excel using C#. I am
working for some assignment, but the query table.add method gives
error.

I wonder what the problem is. I am new to programming of excel and
querytables. We are using Excel 11.0 libraray in C#.



The code snippet:-



static void Main(string[] args)

{

try

{

Excel.Application oXL;

Excel._Workbook oWB;

Excel._Worksheet
oSheet;





// start Excel and get
Application object

oXL = new
Excel.Application();

oXL.Visible = true;





// get a new workbook







oWB =
(Excel._Workbook)(oXL.Workbooks.Add(System.Reflection.Missing.Value));

oSheet =
(Excel._Worksheet)oWB.ActiveSheet;









// I had a problem
here;

// import data to excel
sheet


oSheet.QueryTables.Add(" server=XXXX;database=XXXX;uid=sa;pwd=sa;
",oSheet.get
_Range("A1",
"A1"), "exec prc_X");







// NOTE: for the 3rd
argument I do a stored procedure

//call, but this can
also be a straigh sql statement...







// the QueryTables
collection of the worksheet seems to

//be indexed starting
at 1


oSheet.QueryTables[1].Refresh(true);

oXL.Visible = true;

}

catch (Exception ex)

{

Console.WriteLine
(ex.Message + "\n" + ex.StackTrace);

}



The error message is as following:-



Message           "Exception from HRESULT: 0x800A03EC."
String

_stackTraceString          "   at
System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)\r\n   at Excel.QueryTables.Add(Object Connection, Range
Destination, Object Sql)\r\n   at
ConsoleApplication2.Class1.Main(String[] args) in c:\\documents and
settings\\amitba\\my documents\\visual studio
projects\\consoleapplication2\\class1.cs:line 40"  string



Your prompt assistance is highly expected. Thanks for your time and
effort.


Report this thread to moderator Post Follow-up to this message
Old Post
AMIT
05-30-05 08:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:34 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.