Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'MODULE CONNECTION
- Imports System
- Imports System.Data
- Imports MySql.Data.MySqlClient
- Module connection
- Public connStr As String = "Server=localhost;Database=dbdatabase;User=root;Password=root;"
- Public conn As MySqlConnection = New MySqlConnection(connStr)
- Sub main()
- conn.Open()
- conn.Close()
- Application.Run(New Form1())
- End Sub
- End Module
- 'LOGIN (Button)
- ' ----- [DECLAIRE] -----------------------------
- Dim val As Boolean
- Dim cmd As MySqlCommand
- Dim rdr As MySqlDataReader
- Dim SQL As String = "Select username,password from tuser where username='" & txtusername.Text & "' and password='" & txtpassword.Text & "';"
- ' ----- [OPEN CONNECTION] ------------------------------
- conn.Open()
- cmd = New MySqlCommand(SQL, conn)
- rdr = cmd.ExecuteReader
- ' ----- [READ] ------------------------------
- While (rdr.Read())
- val = True
- End While
- ' ----- [CLOSE CONNECTION] ----------------------------
- rdr.Close()
- conn.Close()
- ' ----- [CONDITION] ---------------------------
- If val = True Then
- Form2.Show()
- Me.Hide()
- Exit Sub
- End If
- ' ----- [FAILD]----------------------------
- '-------------------------------------------
- MsgBox("Incorrect Username Or Password ")
- '-------------------------------------------
- 'SAVE (Button)
- ' ----- [DECLAIRE] --------------------------
- Dim cmd As MySqlCommand
- Dim Sql As String = "INSERT into tuser (username,password) VALUES ('" & txtusername.Text & "','" & txtpassword.Text & "' )"
- ' ----- [OPEN CONNECTION] -----------------------------
- conn.Open()
- ' ----- [READ] ---------------------------------------
- cmd = New MySqlCommand(Sql, conn)
- cmd.ExecuteNonQuery()
- ' ---- [CLOSE CONNECTION] ---------------------------
- conn.Close()
- ' ----- [CALL POPULATE TO REFRESH THE LISTVIEW] -----
- PopulateData()
- '--------- [CLEAR TEXTBOX VALUE] ----------------------
- txtusername.Text = ""
- txtpassword.Text = ""
- 'UPDATE (Button)
- ' ----- [DECLAIRE]
- Dim cmd As MySqlCommand
- Dim Sql As String = "UPDATE tuser SET username = '" & txtusername.Text & "', password = '" & txtpassword.Text & "' where user_id = '" & lblID.Text & "' "
- ' ----- [OPEN CONNECTION]
- conn.Open()
- ' ------ [READ]
- cmd = New MySqlCommand(Sql, conn)
- cmd.ExecuteNonQuery()
- ' ------ [CLOSE CONNECTION]
- conn.Close()
- ' ------ [CALL POPULATE TO REFRESH THE LISTVIEW]
- PopulateData()
- '------- [CLEAR TEXTBOX VALUE]
- txtusername.Text = ""
- txtpassword.Text = ""
- ' ---- [MSG BOX]
- MsgBox("Successfully Updated")
- 'DELETE (Button)
- ' ----- [DECLAIRE] --------------------------
- Dim cmd As MySqlCommand
- Dim Sql As String = "DELETE FROM tuser WHERE user_id = '" & lblID.Text & "' "
- ' ----- [OPEN CONNECTION] -----------------------------
- conn.Open()
- ' ----- [READ] ---------------------------------------
- cmd = New MySqlCommand(Sql, conn)
- cmd.ExecuteNonQuery()
- ' ----- [CLOSE CONNECTION] ---------------------------
- conn.Close()
- ' ----- [CALL POPULATE TO REFRESH THE LISTVIEW] -----
- PopulateData()
- ' ----- [MSG BOX] ---------------------------------------
- MsgBox("Successfully Deleted")
- 'EDIT (Button)
- Dim itm As ListViewItem
- For Each itm In ListView1.SelectedItems
- lblID.Text = itm.Text
- txtusername.Text = itm.SubItems(1).Text
- txtpassword.Text = itm.SubItems(2).Text
- Next
- LISTVIEW MOUSE CLICK
- Dim itm As ListViewItem
- For Each itm In ListView1.SelectedItems
- lblID.Text = itm.Text
- Next
- 'POPULATE DATA (ListView)
- Sub PopulateData()
- ' ----- [DECLAIRE] --------------------------
- Dim lst As ListViewItem
- Dim col As Integer
- Dim cmd As MySqlCommand
- Dim rdr As MySqlDataReader
- Dim Sql As String = "Select * From tuser"
- ListView1.Items.Clear()
- ' ----- [OPEN CONNECTION] -------------------
- conn.Open()
- cmd = New MySqlCommand(Sql, conn)
- rdr = cmd.ExecuteReader
- ' ----- [READ] ------------------------------
- If rdr.HasRows Then
- While rdr.Read()
- lst = ListView1.Items.Add(rdr.GetValue(0).ToString)
- For col = 1 To rdr.FieldCount - 1
- lst.SubItems.Add(rdr.GetValue(col).ToString())
- Next col
- End While
- End If
- ' ----- [CLOSE CONNECTION] -----------------
- conn.Close()
- End Sub
- 'Import this Every Form
- 'Imports System
- 'Imports System.Data
- 'Imports MySql.Data.MySqlClient
Add Comment
Please, Sign In to add comment