Public Class frmaccount
    Dim SelectedUserId = 0

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        myInsert("INSERT INTO `tblaccounts`(`USERNAME`, `PASSWORD`, `USERTYPE`) VALUES ( '" & TextBox1.Text & "', '" & TextBox2.Text & "','" & ComboBox1.Text & "')")

        mySelectQuery("SELECT `ACCOUNTSID`, `USERNAME`, `PASSWORD`, `USERTYPE` FROM `tblaccounts`")
        LoadData(dgv, "addaccount")
        Checkresult("add")
    End Sub

    Private Sub frmaccount_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        mySelectQuery("SELECT `ACCOUNTSID`, `USERNAME`, `PASSWORD`, `USERTYPE` FROM `tblaccounts`")
        LoadData(dgv, "addaccount")

    End Sub

    Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
        SelectedUserId = dgv.CurrentRow.Cells(0).Value
        TextBox1.Text = dgv.CurrentRow.Cells(1).Value
        TextBox2.Text = dgv.CurrentRow.Cells(2).Value
        ComboBox1.Text = dgv.CurrentRow.Cells(3).Value
    End Sub

  

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        myDelete("DELETE FROM `tblaccounts` WHERE `ACCOUNTSID`=" & SelectedUserId)
        mySelectQuery("SELECT `ACCOUNTSID`, `USERNAME`, `PASSWORD`, `USERTYPE` FROM `tblaccounts`")
        LoadData(dgv, "addaccount")
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        myUpdate("UPDATE `tblaccounts` SET `ACCOUNTSID`='" & SelectedUserId & "',`USERNAME`='" & TextBox1.Text & "',`IDNO`='" & TextBox2.Text & "',`USERTYPE`='" & ComboBox1.Text & "' WHERE `ACCOUNTSID`=" & SelectedUserId)
        mySelectQuery("SELECT `ACCOUNTSID`, `USERNAME`, `PASSWORD`, `USERTYPE` FROM `tblaccounts`")
        Checkresult("add")
        Checkresult("Update")
        LoadData(dgv, "addaccount")

    End Sub

    Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

    End Sub
End Class