Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 62,644 times

Contents

Downloads

Related Categories

Query Tool to Excel using C# and .NET - Introduction

Mike Gold

Introduction

Introduction

In the trading world, most traders don't know databases, however they do know spreadsheets, specifically Excel. Once data is inside an Excel spreadsheet, traders can massage the data to suit their needs. The question is, how do you get the data from the database into the spreadsheet? One way is to export the data using provided database tools by the database vendor. One way we can do this is to use .NET's interoperability feature to pull the data directly into the spreadsheet.

Design

The design of the Query2Excel application is fairly straightforward. It consists of a form that allows you to enter your connection information and your query. Inside the form is the ExcelHelper class that allows you to talk directly to excel through the interoperability library. The ExcelHelper class has the minimum number of functions needed to take data from the database and place it into Excel. It has an activation function, Activate, to open and activate excel. It also has several formatting functions (FormatColumn, BoldRow, FormatColumnText, etc.) and it has a method called AddItemToSpreadsheet to allow you to add text to a particular cell in the spreadsheet.

Database connection is done completely through ODBC. ODBC (Open Database Connectivity) will allow you to connect to any database that has an ODBC driver associated with it (e.g. Sql Server, MS Access, Sybase, Oracle, MySQL, and most others.)  The Query2Excel application takes advantage of the OdbcConnection, OdbcCommand, DataSet, and OdbcAdapter classes to connect to the database and perform the query.

Figure 2 - Query2Excel Design Reverse Engineered using the WithClass UML Tool

Mike Gold is President of Microgold Software Inc. and Creator of WithClass 2000 a UML Design Tool for C#. In the last few years Mike has consulted for companies such as Merrill Lynch and Chase Manhattan Bank in New York.  He is been active in developing Visual C++ Applications for 10 years and looks forward to the possibilities in C#.

Mike Gold is President of Microgold Software Inc. and Creator of WithClass 2000 a UML Design Tool for C#. In the last few years Mike has consulted for companies such as Merrill Lynch and Chase Manhattan Bank in New York. He is been active in developing V

Comments

  • Re: Re:

    Posted by KevM on 29 Jun 2006

    Cheers P-Ball

  • Re:

    Posted by P-Ball on 30 May 2006

    Uhm.... try using DateTime.FromOADate(excelDate)


     

  • Posted by nanotechnoloG on 11 Oct 2005

    try this out:
    public class YourClass {

    private static readonly DateTime march1st1900 = new DateTime(1900, 03, 01);
    private static readonly DateTime december31st1899 = new DateTime(1899, 12, 31);...

  • Simple C# code

    Posted by Bambo on 22 Sep 2005


    Hi, everyone.

    I have been out for a while. I am just learning C# and i discovered its a wonderful language.

    I just started my windows application, but i'm having problems starting it.
    Could y...

  • Posted by rishib on 19 Sep 2005

    I am also stuck in this. Did you figure this out ?