Membuat Grafik Berdasarkan Tabel Database VB
Membuat Grafik Berdasarkan Tabel Database VB
Membuat Grafik Berdasarkan Tabel Database VB
Net
pertama buat form seperti berikut yang terdapat satu DataGridView dan Chart, atau
menyesuaikan dengan project yang kalian buat.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms.DataVisualization.Charting
Module MODULKONEKSI
Public cmd As New SqlCommand
Public dttable As New DataTable
Public SQL1 As String
Public dtadapter As SqlDataAdapter = Nothing
Public koneksi As String
Public conn As New SqlConnection
'-------------------Koneksi ke database-----------
Sub konek()
koneksi = "Data Source=MDBK-PC\SQLEXPRESS;Initial
Catalog=JABAL_IT_CONSULTANT;Integrated Security=true"
conn = New SqlConnection(koneksi)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
End Sub
Imports System.Data.SqlClient
Public Class FGrafik
Sub daftar()
Call konek()
Dim sql2 As String
sql2 = "select kode,nama,jumlah from Barang order by Nama asc"
dtadapter = New SqlDataAdapter(sql2, conn)
DataGridView1.Refresh()
Dim AGT As New DataTable
AGT.Clear()
dtadapter.Fill(AGT)
DataGridView1.DataSource = AGT
conn.Close()
End Sub