Xceed Chart for WinForms v4.4 Documentation
Importing from OleDbDataReader

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Data Manipulation > Importing > Importing from OleDbDataReader

The data contained in the data series can be imported from an OleDbDataReader object. This functionality is exposed to the user via the DataSeries. FillFromDataReader and DataSeriesCollection . FillFromDataReader methods.

Importing a Single OleDbDataReader Column into a Data Series

The user can import the data contained in an OleDbDataReader column using the FillFromDataReader method of the DataSeries class. The method receives two arguments: the reader and the column that must be imported. The data contained in the specified column must be compatible with the data series type. See the General Concepts and Terminology topic for a more detailed description of data series compatibility.

The following example demonstrates a single data series import from an OleDbDataReader object. The example assumes that the DataBinging.mdb file contains a table called Sales. The Sales table is supposed to have a column called SalesAmount, which is of type Number-Double.

VB.NET  

' create a bar chart

Dim bar As BarSeries = CType(Chart.Series.Add(SeriesType.Bar), BarSeries)

bar.Appearance.FillMode = AppearanceFillMode.Predefined

bar.Legend.Mode = SeriesLegendMode.DataPoints

 

' create a database connection object using the connection string

OleDbConnection myConnection = New

OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=DataBinding.mdb")

 

' create a database command on the connection using query

Dim myCommand As OleDbCommand =  New OleDbCommand("select * from Sales",myConnection)

 

' open the connection

myCommand.Connection.Open()

 

' create the reader

Dim myReader As OleDbDataReader

myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

 

' import the SalesAmount column into the Values data series

bar.Values.FillFromDataReader(myReader, "SalesAmount")

C#  

// create a bar chart
BarSeries bar = (BarSeries)Chart.Series.Add(SeriesType.Bar);
bar.Appearance.FillMode = AppearanceFillMode.Predefined;
bar.Legend.Mode = SeriesLegendMode.DataPoints;


// create a database connection object using the connection string
OleDbConnection myConnection = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=DataBinding.mdb");


// create a database command on the connection using query
OleDbCommand myCommand = new OleDbCommand("select * from Sales", myConnection);


// open the connection
myCommand.Connection.Open();


// create the reader
OleDbDataReader myReader;
myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);


// import the SalesAmount column into the Values data series
bar.Values.FillFromDataReader(myReader, "SalesAmount");

Importing Multiple OleDbDataReader Columns into a Data Series Collection

The user can simultaneously import the data contained in a set of OleDbDataReader columns into the data series contained in a DataSeriesCollection . This is achieved by using the FillFromDataReader method of the DataSeriesCollection class. The method receives two arguments: the reader and the columns that must be imported. The first specified column is imported into the first data series, the second column into the second series, etc.

The following example demonstrates a multiple data series import from an OleDbDataReader object. The example code simultaneously imports the SalesAmount and ProductName columns (of type Text) into the Values and Labels data series of a bar chart.

VB.NET  

' create a DataSeriesCollection object

Dim arrSeries As DataSeriesCollection =   bar.GetDataSeries(DataSeriesMask.Values Or DataSeriesMask.Labels,DataSeriesMask.None)

 

' create a string array containing the columns which must be imported

Dim arrColumns() As String = {"SalesAmount", "ProductName"}

 

' import the columns into the data series

arrSeries.FillFromDataReader(myReader, arrColumns)

C#  
// create a DataSeriesCollection object
DataSeriesCollection arrSeries = bar.GetDataSeries(DataSeriesMask.Values | DataSeriesMask.Labels, DataSeriesMask.None);
// create a string array containing the columns which must be imported
string[] arrColumns = { "SalesAmount", "ProductName" };
// import the columns into the data series
arrSeries.FillFromDataReader(myReader, arrColumns);

Related Examples

Windows Forms: Data Manipulation\Importing\From OleDbDataReader

See Also

Basic Series Functionality | DataSeries | DataSeriesCollection