Imports System.Data.OleDb
Public Class SupplierForm
    Private dbc As New OleDbConnection(conStr)
    Public Sub showcli()
        Dim dba As New OleDbDataAdapter("SELECT * FROM tbClient", dbc)
        Dim dbset As New DataSet
        dba.Fill(dbset)
        Me.DataGridView1.DataSource = dbset.Tables(0).DefaultView

    End Sub



    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        showcli()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If MessageBox.Show("Add New client?", "Add Client", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.No Then
            
            Exit Sub

        End If
        Dim incmd As New OleDbCommand("INSERT INTO tbClient(CName, CAddress, CContactNumber) VALUES('" & Me.TextBox1.Text & "', '" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "')", dbc)
        dbc.Open()
        incmd.ExecuteNonQuery()
        dbc.Close()

        MessageBox.Show("Client was Successfully Added to List!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Me.TextBox1.Text = ""
        Me.TextBox2.Text = ""
        Me.TextBox3.Text = ""

        showcli()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If MessageBox.Show("Delete Selected Client?", "Delete Client", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.No Then

            Exit Sub
        Else
            Dim delc As New OleDbCommand("DELETE * FROM tbClient WHERE CID=" & Me.DataGridView1.CurrentRow.Cells(0).Value & "", dbc)
            dbc.Open()
            delc.ExecuteNonQuery()
            dbc.Close()
            MessageBox.Show("Client was Successfully Deleted!")
            showcli()




        End If
       

    End Sub
End Class