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: 2
Default Displaying a dataset or datatable in Excel

There's something I think ought to be easy, but I can't find a way to do it.
Either there's something wrong with the way I'm searching, or there's a
reason it can't be done easily.

What I want is to create an excel addin that, when the user opens a
spreadsheet , it goes out and fetches some data from a database, and displays
it in a table. Pretty straightforward. Here's some code:


void Application_WorkbookOpen(Microsoft.Office.Interop. Excel.Workbook wb)
{//I've also attached this to other events. The "open" event isn't
the key part. It doesn't do anything in any event.

string connstring="Integrated Security=SSPI;
database=MyInventoryDB; Data Source=MyServer\\MyInventory";

System.Data.SqlClient.SqlDataAdapter da=new
System.Data.SqlClient.SqlDataAdapter("Select * from
PlantInventory",connstring);
System.Data.DataSet ds=new System.Data.DataSet();
da.Fill(ds);
Excel.Worksheet
activeWorksheet=((Excel.Worksheet)Application.Acti veSheet);
Excel.Range
inventoryrange=activeWorksheet.get_Range("C6",miss ing);
//Here's the line I know doesn't work, but I think something
sort of like it ought to.
inventoryrange.Value2=ds.Tables[0];
//or maybe create a range and set a datasource.
}

So, the key is that I want to use a range of cells that I define sort of
like I would use a datagridview. I want to fetch a table, as above, and then
tell the sheet to display the data in a given range.

When googling, I seem to find people who have iterated through each row in
the returned datatable, and each column within the row, and filled in one
cell at a time. I know how to do that, but it seems like this would be so
commonly requested that there ought to be a simple, one or two step command
to make this happen. Any suggestions?
 
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
Populate date into excel from DataSet/DataTable Dhans Excel Programming 1 November 19th 09 10:37 AM
How to Transfer an Excel Range to an ADO.Net DataSet or DataTable in VB.Net? TCook Excel Programming 4 November 3rd 06 12:28 PM
assign dataset to matching dataset Michael Dirksen Excel Programming 0 June 16th 06 04:34 PM
Displaying the size of the dataset currently in memory [email protected] Excel Programming 0 April 16th 06 02:45 PM
Converting A Quarterly Dataset to Weekly Dataset Dan Thompson Excel Programming 5 November 25th 05 09:27 PM


All times are GMT +1. The time now is 02:41 PM.

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"