Imports MySql.Data.MySqlClient
'Simple CRUD application in Visual Basic NET and MySQL with Crystal Report
' Written By Mr. Jake R. Pomperada,MAED-IT
' January 19, 2019 Friday
' jakerpomperada@gmail.com and jakerpomperada@aol.com
' http://www.jakerpomperada.com
Public Class Form1
Dim str As String = "server=localhost; uid=root; pwd=; database=dbprofile"
Dim con As New MySqlConnection(Str)
Sub loadme()
Label6.Text = "Date : " & Date.Today
Label7.Text = "Time : " & DateTime.Now.ToString("HH:mm:ss tt")
Dim query As String = "select * from profile"
Dim adpt As New MySqlDataAdapter(query, con)
Dim ds As New DataSet()
adpt.Fill(ds, "users")
DataGridView1.DataSource = ds.Tables(0)
con.Close()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox1.Focus()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
loadme()
End Sub
Private Sub btn_add_Click(sender As Object, e As EventArgs) Handles btn_add.Click
Dim cmd As MySqlCommand
con.Open()
Try
cmd = con.CreateCommand
cmd.CommandText = "insert into profile(id,name,mobile,email)values(@id,@name,@mobile,@email);"
cmd.Parameters.AddWithValue("@id", TextBox1.Text)
cmd.Parameters.AddWithValue("@name", UCase(TextBox2.Text))
cmd.Parameters.AddWithValue("@mobile", TextBox3.Text)
cmd.Parameters.AddWithValue("@email", LCase(TextBox4.Text))
cmd.ExecuteNonQuery()
MessageBox.Show("Record has been saved successfully", "Save Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
loadme()
Catch ex As Exception
End Try
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim row As DataGridViewRow = DataGridView1.CurrentRow
Try
TextBox1.Text = row.Cells(0).Value.ToString()
TextBox2.Text = row.Cells(1).Value.ToString()
TextBox3.Text = row.Cells(2).Value.ToString()
TextBox4.Text = row.Cells(3).Value.ToString()
Catch ex As Exception
End Try
End Sub
Private Sub btn_update_Click(sender As Object, e As EventArgs) Handles btn_update.Click
Dim cmd As MySqlCommand
con.Open()
Try
cmd = con.CreateCommand()
cmd.CommandText = "update profile set name=@name,mobile=@mobile,email=@email where id=@id;"
cmd.Parameters.AddWithValue("@id", TextBox1.Text)
cmd.Parameters.AddWithValue("@name", UCase(TextBox2.Text))
cmd.Parameters.AddWithValue("@mobile", TextBox3.Text)
cmd.Parameters.AddWithValue("@email", LCase(TextBox4.Text))
cmd.ExecuteNonQuery()
MessageBox.Show("Record has been updated successfully", "Update Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
loadme()
Catch ex As Exception
End Try
End Sub
Private Sub btn_delete_Click(sender As Object, e As EventArgs) Handles btn_delete.Click
Dim cmd As MySqlCommand
con.Open()
Try
Select Case MsgBox("Are you sure to delete this record?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Delete Record")
Case MsgBoxResult.Yes
cmd = con.CreateCommand()
cmd.CommandText = "delete from profile where id=@id;"
cmd.Parameters.AddWithValue("@id", TextBox1.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Record has been deleted successfully", "Delete Record", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
loadme()
Case MsgBoxResult.No
loadme()
End Select
Catch ex As Exception
End Try
End Sub
Private Sub btn_reset_Click(sender As Object, e As EventArgs) Handles btn_reset.Click
loadme()
End Sub
Private Sub btn_quit_Click(sender As Object, e As EventArgs) Handles btn_quit.Click
Select Case MsgBox("Are you sure to quit program?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Quit Program")
Case MsgBoxResult.Yes
End
Case MsgBoxResult.No
loadme()
End Select
End Sub
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles txtsearch.TextChanged
Dim adapater As MySqlDataAdapter
Dim ds As New DataSet
Try
con.Open()
adapater = New MySqlDataAdapter("select * from profile where name like '%" & txtsearch.Text & "%'", con)
adapater.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
con.Close()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
Catch ex As Exception
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_about.Click
MessageBox.Show("This Program is Created By Mr. Jake R. Pomperada" & vbNewLine _
& vbNewLine _
& "Date : January 17, 2019 Thursday" & vbNewLine & vbNewLine _
& "Bacolod City, Negros Occidental Philippines" & vbNewLine _
& vbNewLine _
& "Website : http://www.jakerpomperada.com " & vbNewLine _
& vbNewLine _
& "Email Address : jakerpomperada@gmail.com" & vbNewLine _
, "About This Program", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub btn_print_Click(sender As Object, e As EventArgs) Handles btn_print.Click
Form2.Show()
End Sub
End Class