For i = 2014 To 2050
sql = "SELECT DISTINCT(YEAR(sale_date)) FROM Sale_head WHERE YEAR(sale_date) =" & i
command = New SqlCommand(sql, connection)
Dim y As Integer = command.ExecuteScalar()
If Not y = Nothing Then
sql = "SELECT SUM(sale_net) FROM Sale_head WHERE YEAR(sale_date)='" & y & "'" 'รายรับ
command = New SqlCommand(sql, connection)
Dim ss As Double = command.ExecuteScalar()
sql = "SELECT SUM(buy_cost) FROM Buyproduct WHERE YEAR(buy_date)='" & y & "'" 'รายจ่าย
command = New SqlCommand(sql, connection)
Dim sb As Double = command.ExecuteScalar()
Dim sumsb1 As Double = ss - sb
DataGridView1.Rows.Add(New String() {i + 543, ss, sb, sumsb1}) '--เพิ่มรายการที่ละแถว
End If
Next
sql = "SELECT distinct(pro_id) FROM Product_return WHERE YEAR(pr_date)='" & y & "'"
command = New SqlCommand(sql, connection)
selectProid = command.ExecuteReader()
While selectProid.Read
MessageBox.Show(selectProid(0))
End While
selectProid.Close()