.netCHARTING v10.5 Documentation
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 that is 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 any supported data sources when a ConnectionString is specified. Supported data sources include

  • MS Access
  • MS SQL
  • Oracle*
  • mySQL*
  • ODBC*
  • Excel
  • XML

*Available with .net framework version 2.0 only.

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.

If you wish to use MS Access sample database on a x64 system, you must set "Enable 32-bit Application" to true in the Application Pool/Advanced settings in IIS.

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:

  • Text
  • Date
  • Number
  • LongNumber
  • Currency
  • Double

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 DataEngine with the xml document file name:

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

Other Sources

Firebird and other unsupported sources

.netCHARTING can also parse supported data objects generated from any data source using the respective .net providers. 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

  • DataSet
  • DataTable
  • DataView
  • String (Raw xml)
  • String (xml file name)
  • XmlDocument


These objects are consumed by the DataEngine's Data property.

Example:

[C#]

de.Data = myDataTable;
[Visual Basic]

de.Data = myDataTable