Glossary Item Box

.netCHARTING v3.3 Documentation Send comments on this topic.

Connecting to Data

Introduction

.netCHARTING provides the DataEngine object which can be used to automatically obtain data from a variety of data sources. The DataEngine returns a SeriesCollection object which contains data formatted appropriately to be consumed by the chart.

The DataEngine object is instantiated like so:
[C#]
DataEngine de = new DataEngine();
[Visual Basic]
Dim de As New DataEngine()

Using data sources.

The DataEngine object internally connects to supported data sources when a ConnectionString is specified. Supported data sources include Access, SQL, Excel, and XML.

Unsupported data sources can also be utilized by supplying the DataEngine with a data object such as a DataTable.

When connecting to supported data sources data is queried by setting the SqlStatement property of the DataEngine.

Examples

There are different methods of connecting to specific data sources. The following section demonstrates how each supported data source can be utilized.

Access Database

[C#]
de.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;user id=;password=
                        ; data source=" + Server.MapPath("db.mdb");
// A connection string shortcut for access databases is also available.
de.ConnectionString = "db.mdb";
de.SqlStatement = @"SELECT OrderDate,Sum(Total) FROM Orders ";
[Visual Basic]
de.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;user id=;password=;"_
                        & "data source=" & Server.MapPath("db.mdb")
' A connection string shortcut for access databases is also available.
de.ConnectionString = "db.mdb"
de.SqlStatement = "SELECT OrderDate,Sum(Total) FROM Orders "

SQL Database

[C#]
de.ConnectionString = @"server=server name or IP;uid=username;pwd=password;database=database name"; 
de.SqlStatement = @"SELECT OrderDate,Sum(Total) FROM Orders ";
[Visual Basic]
de.ConnectionString = "server=server name or IP;uid=username;pwd=password;database=database name" 
de.SqlStatement = "SELECT OrderDate,Sum(Total) FROM Orders "

 

Stored Procedure

[C#]
de.StoredProcedure = "myProcedure";
de.AddParameter("@STARTDATE","3/10/02 12:00:00 AM",FieldType.Date);
[Visual Basic]
de.StoredProcedure = "myProcedure"
de.AddParameter("@STARTDATE","3/10/02 12:00:00 AM",FieldType.Date)

The AddParameter method is optionally used in conjunction with the StoredProcedure property to specify any number of parameters for the stored procedure. The following parameter types are supported:

Excel Files

 

[C#]
de.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source= " + Server.MapPath("myData.xls")
                        + ";Extended Properties=\"Excel 8.0;\"";
de.SqlStatement= @"Select Periods,Sales from [Yearly Summary$]";
[Visual Basic]
de.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("myData.xls") _
                        & ";Extended Properties=\"Excel 8.0;\""
de.SqlStatement= "Select Periods,Sales from [Yearly Summary$]"

XML Files

Xml files can be used as data sources by setting the Data property of the data engine like so:

[C#]
de.Data = "Orders.xml";
[Visual Basic]
de.Data = "Orders.xml"

Other Sources

Oracle, mySQL, Firebird and other unsupported sources

.netCHARTING can also parse data objects generated from any data source in ADO.NET by using the DataEngine's Data property. If you can access your data in your .NET application you can chart it with .netCHARTING in a few simple lines of code.

Supported Data Objects


Example:

[C#]

de.Data = myDataTable;
[Visual Basic]

de.Data = myDataTable

2002 - 2005 Webavail Productions Inc. & Corporate Web Solutions Ltd.. All Rights Reserved.