0% found this document useful (0 votes)
19 views1 page

'Import Required Libraries: Form2 Eventargs

This code is creating a bar chart in a Windows Form that displays the number of units in stock for each product using data from a SQL database. It imports required libraries, connects to the database, runs a SQL query to retrieve product names and unit counts, loads the data into a dataset, creates a bar chart control, sets the data source of the chart to the dataset table, and configures the chart series to use the product names and unit counts from the data.

Uploaded by

Nouredine Fred
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

'Import Required Libraries: Form2 Eventargs

This code is creating a bar chart in a Windows Form that displays the number of units in stock for each product using data from a SQL database. It imports required libraries, connects to the database, runs a SQL query to retrieve product names and unit counts, loads the data into a dataset, creates a bar chart control, sets the data source of the chart to the dataset table, and configures the chart series to use the product names and unit counts from the data.

Uploaded by

Nouredine Fred
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Imports System.

Data
Imports System.Data.SqlClient
Imports System.Windows.Forms.DataVisualization.Charting
'Import Required Libraries

Public Class Form2

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim strConn As String = "Data Source=DELL-PC;Initial Catalog=gestion A;Integrated


Security=True"

Dim conn As New SqlConnection(strConn)

Dim sqlProducts As String = "SELECT ProductName, UnitsInStock FROM Products"


Dim da As New SqlDataAdapter(sqlProducts, conn)
Dim ds As New DataSet()
da.Fill(ds, "Products")

Dim ChartArea1 As ChartArea = New ChartArea()


Dim Legend1 As Legend = New Legend()
Dim Series1 As Series = New Series()
Dim Chart1 = New Chart()
Me.Controls.Add(Chart1)

ChartArea1.Name = "ChartArea1"
Chart1.ChartAreas.Add(ChartArea1)
Legend1.Name = "Legend1"
Chart1.Legends.Add(Legend1)
Chart1.Location = New System.Drawing.Point(13, 13)
Chart1.Name = "Chart1"
Series1.ChartArea = "ChartArea1"
Series1.Legend = "Legend1"
Series1.Name = "Series1"
Chart1.Series.Add(Series1)
Chart1.Size = New System.Drawing.Size(800, 400)
Chart1.TabIndex = 0
Chart1.Text = "Chart1"

Chart1.Series("Series1").XValueMember = "ProductName"
Chart1.Series("Series1").YValueMembers = "UnitsInStock"

Chart1.DataSource = ds.Tables("Products")
End Sub
End Class

You might also like