
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