The user can import the data contained in an OleDbDataReader column with the help of the FillFromDataReader method of the NDataSeries class. The method receives two arguments - the reader and the column, which must be imported. The data contained in the specified column must be compatible with the data series type (see the topic for a more detailed description of data series compatibility).
The following example demonstrates a single data series import from an OleDbDataReader. 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.
C# |
Copy Code
|
---|---|
// 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); // create a bar chart NBarSeries bar = (NBarSeries)chart.Series.Add(SeriesType.Bar); // import the SalesAmount column into the Values data series bar.Values.FillFromDataReader(myReader, "SalesAmount"); |
Visual Basic |
Copy Code
|
---|---|
' 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) ' create a bar chart Dim bar As NBarSeries = chart.Series.Add(SeriesType.Bar) ' import the SalesAmount column into the Values data series bar.Values.FillFromDataReader(myReader, "SalesAmount") |