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: 34
Default Binding a DataSet to a ListObject


The code below successfully binds the data in the ListObject listTbl to the
data in the DataTable twsTable. However, it does not bind the column names
or the formatting of twsTable to listTbl. In other words, the column names
on listTbl show up on the Excel spreadsheet as "Column 1", "Column 2", etc.,
and the formatting/column widths is the default for the Excel spreadsheet.
How do I get the column names and formatting from the DataTable bound to the
ListObject?

Dim listTbl As Microsoft.Office.Tools.Excel.ListObject
Dim twsTable As DataTable

'fill twsTable with data and schema from database on SQL Server
fromtwsTable.CommandText = "SELECT * FROM [TWS IntraDay] ORDER BY Ticker"
twsTableDa.Fill(CosDB_ds, "TWS IntraDay")
twsTable = CosDB_ds.Tables("TWS IntraDay")
twsTableDa.FillSchema(twsTable, SchemaType.Source)

'add a ListTable to Excel
listTbl = Globals.Sheet1.Controls.AddListObject(Globals.Shee t1.Range("A2"),
"StockTable")

'bind the list table to the DataTable twsTable
listTbl.DataSource = twsTable


Incidentally, I tried the following:

Dim listTblCols As Excel.ListColumns = listTbl.ListColumns
For c = 0 To twsTable.Columns.Count - 1
listTblCols(c).Name = twsTable.Columns(c).ColumnName
Next c

This returns a "Bad index" COM error when I try to assign or read a .Name
value from listTblCols. When I add listTblCols to the Watch window, it shows
it's m_ObjectToDataMap as null and says "Children could not be evaluated".
However, listTblCols.Count correctly returns 11 for the column count.

--
Ed
 
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
ListObject binding samsam Excel Programming 0 September 19th 06 08:05 AM
assign dataset to matching dataset Michael Dirksen Excel Programming 0 June 16th 06 04:34 PM
Converting A Quarterly Dataset to Weekly Dataset Dan Thompson Excel Programming 5 November 25th 05 09:27 PM
Late Binding examples of binding excel application HeatherO Excel Programming 13 March 17th 05 08:19 AM
EARLY binding or LATE binding ? jason Excel Programming 6 February 26th 04 04:57 PM


All times are GMT +1. The time now is 08:39 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"