Imports System.Data.SqlClient
Module Module1
    Public con As New SqlConnection
    Public connection As String
    Public user As String
    Public action As String
    Public logger As String
    Public nam As String
    Public lnam As String
    Public lnum As String
    Public lgoods As String
    Public lqty As String
    Public ldate As String
    Public lprice As String
    Public lbal As String
    Public d As String
    Public n As Integer
    Public dvalue As Double = 0.0
    Public dval As Double
    Public dget As Double
    Public dcon As Double = 0.0
    Public dresult As Double
    Public Enum AddRec
        AddRecord = 0
        EditRecord = 1
    End Enum
    Public Function GetCon() As String
        connection = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database2.mdf;Integrated Security=True;User Instance=True"
        Return connection
    End Function
    Public Sub opencon()
        If con.State = ConnectionState.Closed Then
            con.ConnectionString = GetCon()
            con.Open()
            Exit Sub
        End If
    End Sub
    Public Sub closecon()
        If con.State = ConnectionState.Open Then
            con.Close()
            Exit Sub
        End If
    End Sub
    Public Sub loadtype()
        Try
            Call opencon()
            Dim myd As New SqlDataAdapter
            With myd
                .SelectCommand = New SqlCommand
                .SelectCommand.CommandText = "SELECT category ,SUM(qty)As qty FROM stock GROUP BY category HAVING SUM(qty) < 1 "
                .SelectCommand.Connection = con
            End With

            Dim dt2 As New DataTable

            myd.Fill(dt2)
            FrmOutofStock.dtgv.DataSource = dt2
           
            Call closecon()
           
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        
    End Sub




End Module


