|   Contact  
WebChartLogo

Sample of showing Access Database using VB.NET


This sample shows how easy is to create a Chart for Access Database using DataBinding in the Chart Control
This is how the chart looks like, just copy/paste the code into notepad and save it as .aspx:

Code

The code below shows how you can bind a DataReader to the control. Notice that since we are using a IDataReader which is the interface for DataReaders, we would be able to replace the GetDataReader method to return a SqlDataReader or any other Reader to bind the data to.
<%@ Page Language="VB" %>
<%@ Register tagPrefix="web" Assembly="WebChart" Namespace="WebChart" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat=server>
Sub Page_Load(o as object, e as EventArgs) 
  Dim reader As IDataReader = GetReader()

  Dim chart As New SmoothLineChart()
  chart.DataXValueField = "Product"
  chart.DataYValueField = "Price"
  chart.DataSource = reader
  chart.DataBind()
  reader.Close()

  ChartControl1.Charts.Add(chart)
  ChartControl1.RedrawChart()
End Sub

Function GetReader() As IDataReader 
  Dim connection As new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Mode=Read")
  Dim command As new OleDbCommand("SELECT Top 10 [ProductName] As Product,[UnitPrice] As Price FROM Products order by UnitPrice desc", connection)
  connection.Open()
  Return command.ExecuteReader(CommandBehavior.CloseConnection)
End Function
</script>
<html>
<body>
<form runat="server">
  
<web:ChartControl runat="server" Width="800px" Height="600px" 
        id
="ChartControl1" HasChartLegend="false" BottomChartPadding=80 ChartPadding=20>
        
<XAxisFont ForeColor="Black" StringFormat="Center,Center,Character,DirectionVertical" Font="Tahoma, 8pt, style=bold" />
  
</web:ChartControl>
</form>
</body>
</html>
 

Carlos Aguilar Mares © 2017