|
How to get data from SQL database to ChartDirector in VB.NET |
Posted by cici on Dec-16-2014 03:57 |
|
Hi,
I already can show data to datagridview. How can I show my data to ChartDirect?
This is my code:
Imports System.Data
Imports System.Data.SqlClient
Imports ChartDirector
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles
Me.Load
Dim connectionString As String = "Data Source=My-PC;" & _
"Initial Catalog=FF;Integrated Security=True"
Dim sql As String = "SELECT ZONE,TEMP,THICK FROM TEST"
Dim connection As New SqlConnection(connectionString)
Dim dataadapter As New SqlDataAdapter(sql, connection)
Dim ds As New System.Data.DataSet()
Dim cmd As New SqlCommand
Try
connection.Open()
dataadapter.Fill(ds, "TEST")
DataGridView1.Refresh()
cmd = New SqlCommand(sql, connection)
cmd.ExecuteNonQuery()
connection.Close()
DataGridView1.DataSource = ds.Tables(0)
'dtPVC = ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class |
Re: How to get data from SQL database to ChartDirector in VB.NET |
Posted by Peter Kwan on Dec-17-2014 01:18 |
|
Hi cici,
Your data are in the DataTable object ds.Tables(0). Your code is currently displaying this
DataTable in a DataGridView. To use these data in charts, one method is to pass the
DataTable to the ChartDirector DBTable object to obtain the data series to plot the chart,
as in the "Simple Database Chart" sample code:
http://www.advsofteng.com/doc/cdnet.htm#dbsample1.htm
For example:
Dim table As DBTable = New DBTable(ds.Tables(0))
'Assume the first column is the labels for the x-axis
Dim labels() As String = table.getColAsString(0)
'Assume the second column is the data values
Dim data() As String = table.getCol(0)
.... now you can use labels and data to plot charts .....
Hope this can help.
Regards
Peter Kwan |
Re: How to get data from SQL database to ChartDirector in VB.NET |
Posted by cici on Dec-17-2014 23:45 |
|
Thank you Peter, I already made it! |
Re: How to get data from SQL database to ChartDirector in VB.NET |
Posted by karthik on Aug-17-2018 15:12 |
|
Dear Bro will you please help me to get chart from database? I am newbie so will u please send me your code how to add the database with chartdirector chart |
Re: How to get data from SQL database to ChartDirector in VB.NET |
Posted by Peter Kwan on Aug-18-2018 12:19 |
|
Hi karthik,
The documentation in this thread has been moved to:
https://www.advsofteng.com/doc_v51/cdnet.htm#dbsample1.htm
The sample code uses the System.Data.OleDb.OleDbConnection. You can use the same type of connection, and replacing the connection string with the one suitable for your SQL server, or you can use other types of connection (eg. System.Data.SqlClient.SqlConnection).
If you are not sure how to connect to a database, you may refer to the following Microsoft page. It describes various connection methods (SqlClient, ODBC, OLE DB).
https://docs.microsoft.com/en-us/dotnet/api/system.data.idbconnection?view=netframework-4.7.2
Hope this can help.
Regards
Peter Kwan |
|