Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
Display a Windows Form from Excel 2003 #85
Chapter 11, Visual Studio Tools for Office
|
379
HACK
conn.Close( );
//Output customers order data to Excel
for (int i = 0; i != 12; i++)
{
for (int j = 0; j !=2; j++)
{
this.excelCode.EchoStringToCell(OrderCounts[i,j],
new int[2] {i+1,j+1});
}
}
}
In the method that handles the click event of the command button, you are
going to connect to the SQL server and retrieve the counts of orders for a
particular client for the selected year. Notice that by using the
SelectedValue
property of the combo boxes, you have the CustomerID field. Later, when
you are building the chart, you will use both the
Text property and the
SelectedValue property to label your work in the Excel sheets.
There are a couple of ways that you could have handled the output of the
data for each month. Here, the use of an array, initialized to the default val-
ues, allows you to control what is displayed for the month names without
writing too much Transact-SQL. Now all you need to do is get SQL Server
to return the rows where data exists. The other option would be for SQL to
return results for each month and then write the data directly from the data
reader to the Excel worksheet.
Finally, to send the data to the Excel worksheet, you need to move through
the two dimensions of the array and call the
EchoStringToCell method that
you will create in the next section. This function will take a
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page