VB.NET Insert Update Delete with MySQL Database Metro UI Theme + Source Code

VB.NET For beginner : how toCRUD operations (insert,read,update,delete) in vb.net with mysql database and Metro theme UI windows Form? download source code simple CRUD applications in sector code.

VB.NET for beginners  - How to create simple CRUD application (Create,Read,Update,Delete) in vb.net and using MySQL database ODBC connection with Metro Framework UI theme design? this tutorial has been create before, Please read CRUD Tutorial with MySQL Database, but today i'll make a new version and change the default theme to a simple interface with metro framework theme.

Read : How to Change default windows form with Metro Framework Theme
How to Create MySQL Database
How to Make A connection Using ODBC Driver

we will create a simple CRUD operations step by step, so you can easy to follow how to make this simple.

Create a New Project

Just create a new project with a name "CRUDmetro", and lets design Form1.vb look like this

VB.NET Insert Update Delete with MySQL Database

Just leave the Form1.vb for a moment, we will create new module for our connections.

Source Code Module Connections

So lets create new module and rename it with "ModuleConnections.vb" and write all source code above.
Imports System.Data.Odbc ' import namespace of ODBC
Module ModuleConnections
    Public connections As OdbcConnection ' declarations for our connections
    Sub OpenConnection()
        Try
            ' you must hasbeen install MySQL ODBC driver on your computer
            ' then create connection to our database (MySQL)
            ' just see on the descriptions how to make a connections using ODBC Driver
            connections = New OdbcConnection("DSN=delta_db;MultipleActiveResultSets=True")
            If connections.State = ConnectionState.Closed Then
                connections.Open() ' open the connections
            End If
        Catch ex As Exception
            MsgBox("Connection Failed !") ' if connection is failed
        End Try
    End Sub
End Module
If you has been done with our module for connections to a database, back to Form1.vb and lets complete all the code.

With form1.vb, first please import name space of ODBC driver.
Imports System.Data.Odbc ' import namespace of ODBC
and declarations our variable for a new data or old data, so this variable will be show when we will create a new data and when we update the old data. i hope you understand, just write the variable above the class form1.vb
Dim NewData As Boolean ' declarations New data for save new data, or update the data

Source Code Sub Load Data

load data will biand all data from database to a GridViews, just write this code
    Sub LoadData()
        ' its for load all data into gridviews
        OpenConnection() ' open our connection
        Dim da As New OdbcDataAdapter("SELECT * FROM karyawan", connections)
        Dim ds As New DataSet
        ds.Clear()
        da.Fill(ds, "karyawan")
        MetroGrid1.DataSource = ds.Tables("karyawan") ' set datasource of our gridview
        da.Dispose()
        connections.Close()
    End Sub

Source Code Sub SenToTextBox

Its will change the textbox value with any value from datagridview
    Sub senToTextBox(ByVal x As Integer)
        'its for get value from datagridview into textbox        
        Try
            MetroTextBox1.Text = MetroGrid1.Rows(x).Cells(0).Value
            MetroTextBox2.Text = MetroGrid1.Rows(x).Cells(1).Value
            MetroTextBox3.Text = MetroGrid1.Rows(x).Cells(2).Value
            MetroTextBox4.Text = MetroGrid1.Rows(x).Cells(3).Value
            MetroTextBox5.Text = MetroGrid1.Rows(x).Cells(4).Value
            MetroTextBox6.Text = MetroGrid1.Rows(x).Cells(5).Value
        Catch ex As Exception
        End Try
    End Sub

Source Code Sub Clear The TextBox

    Sub ClearTextBox()
        MetroTextBox1.Text = "" ' its for clear the textbox
        MetroTextBox2.Text = ""
        MetroTextBox3.Text = ""
        MetroTextBox4.Text = ""
        MetroTextBox5.Text = ""
        MetroTextBox6.Text = ""
        MetroTextBox1.Focus()
    End Sub

Source Code Setting Width of The DataGridView Columns

    Sub SettingGrid()
        MetroGrid1.Columns(0).Width = 40 ' setting width of our column
        ' you can setting more of your datagrid columns
    End Sub

Source Code Functions To Save or Update Or Delete data

    Private Sub RunSQL(ByVal sql As String) ' create functions for save or update data
        Dim cmd As New OdbcCommand
        OpenConnection() ' open our connection
        Try
            cmd.Connection = connections
            cmd.CommandType = CommandType.Text
            cmd.CommandText = sql
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            connections.Close()
            MsgBox("Data Hasbeen saved !", vbInformation)
        Catch ex As Exception
            MsgBox("Error when saving data !" & ex.Message)
        End Try
    End Sub

Source Code Form Load

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
        SettingGrid()
        NewData = True ' its mean we will create a new data with query "INSERT"
        ' if new data = false, its mean we make a query "UPDATE"
    End Sub

Source Code New Button (Button1)

    Private Sub MetroButton1_Click(sender As Object, e As EventArgs) Handles MetroButton1.Click
        NewData = True
        ClearTextBox()
    End Sub

Source Code Save Button (Button2)

    Private Sub MetroButton2_Click(sender As Object, e As EventArgs) Handles MetroButton2.Click
        Dim savaedata As String
        Dim massege As String
        If NewData Then
            massege = MsgBox("Are you sure to add new data to database?", vbYesNo + vbInformation, "Information")
            If massege = vbNo Then
                Exit Sub
            End If
            savaedata = "INSERT INTO karyawan(id_karyawan,nama_karyawan,nik,jabatan,no_telphone,alamat) " _
            + "Values('" & MetroTextBox1.Text & "','" & MetroTextBox2.Text & "','" & MetroTextBox3.Text & "','" & MetroTextBox4.Text & "','" & MetroTextBox5.Text & "','" & MetroTextBox6.Text & "')"
        Else
            massege = MsgBox("Are you sure to UPDATE data to database?", vbYesNo + vbInformation, "Information")
            If massege = vbNo Then
                Exit Sub
            End If
            savaedata = "UPDATE karyawan SET nama_karyawan='" & MetroTextBox2.Text & "' " _
            + ",nik='" & MetroTextBox3.Text & "' " _
            + ",jabatan='" & MetroTextBox4.Text & "' " _
            + ",no_telphone='" & MetroTextBox5.Text & "' " _
            + ",alamat='" & MetroTextBox6.Text & "' where id_karyawan='" & MetroTextBox1.Text & "'"
        End If
        RunSQL(savaedata)
        MetroGrid1.Refresh()
        LoadData() ' insert data again after you update the data
    End Sub

Source Code Delete Button (Button3)

    Private Sub MetroButton3_Click(sender As Object, e As EventArgs) Handles MetroButton3.Click
        Dim delete As String
        Dim message As String
        message = MsgBox("Are you sure want to delete this data?  ", vbExclamation + vbYesNo, "warning")
        If message = vbNo Then Exit Sub
        delete = "DELETE from karyawan where id_karyawan='" & MetroTextBox1.Text & "'"
        RunSQL(delete) ' delet functions
        MetroGrid1.Refresh()
        LoadData() ' insert data again after you update the data
    End Sub

Source Code Exit Button (Button4)

    Private Sub MetroButton4_Click(sender As Object, e As EventArgs) Handles MetroButton4.Click
        Me.Close()
    End Sub

Source Code DataGridView Cell Click Event

    Private Sub MetroGrid1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles MetroGrid1.CellClick
        senToTextBox(e.RowIndex) ' send value to textbox
        NewData = False
    End Sub
So we have done with simple project CRUD Operations with MySQL database and Metro Framework UI Themes, But wait.. i'll show you all complete the Source Code Form1.vb, just view and write all complete code bellow.
Imports System.Data.Odbc
Public Class Form1
    Dim NewData As Boolean ' declarations New data for save new data, or update the data
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
        SettingGrid()
        NewData = True ' its mean we will create a new data with query "INSERT"
        ' if new data = false, its mean we make a query "UPDATE"
    End Sub
    Sub LoadData()
        ' its for load all data into gridviews
        OpenConnection() ' open our connection
        Dim da As New OdbcDataAdapter("SELECT * FROM karyawan", connections)
        Dim ds As New DataSet
        ds.Clear()
        da.Fill(ds, "karyawan")
        MetroGrid1.DataSource = ds.Tables("karyawan") ' set datasource of our gridview
        da.Dispose()
        connections.Close()
    End Sub
    Sub senToTextBox(ByVal x As Integer)
        'its for get value from datagridview into textbox        
        Try
            MetroTextBox1.Text = MetroGrid1.Rows(x).Cells(0).Value
            MetroTextBox2.Text = MetroGrid1.Rows(x).Cells(1).Value
            MetroTextBox3.Text = MetroGrid1.Rows(x).Cells(2).Value
            MetroTextBox4.Text = MetroGrid1.Rows(x).Cells(3).Value
            MetroTextBox5.Text = MetroGrid1.Rows(x).Cells(4).Value
            MetroTextBox6.Text = MetroGrid1.Rows(x).Cells(5).Value
        Catch ex As Exception
        End Try
    End Sub
    Private Sub MetroGrid1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles MetroGrid1.CellClick
        senToTextBox(e.RowIndex) ' send value to textbox
        NewData = False
    End Sub
    Sub SettingGrid()
        MetroGrid1.Columns(0).Width = 40 ' setting width of our column
    End Sub
    Sub ClearTextBox()
        MetroTextBox1.Text = "" ' its for clear the textbox
        MetroTextBox2.Text = ""
        MetroTextBox3.Text = ""
        MetroTextBox4.Text = ""
        MetroTextBox5.Text = ""
        MetroTextBox6.Text = ""
        MetroTextBox1.Focus()
    End Sub
    Private Sub MetroButton1_Click(sender As Object, e As EventArgs) Handles MetroButton1.Click
        NewData = True
        ClearTextBox()
    End Sub
    Private Sub RunSQL(ByVal sql As String) ' create functions for save or update data
        Dim cmd As New OdbcCommand
        OpenConnection() ' open our connection
        Try
            cmd.Connection = connections
            cmd.CommandType = CommandType.Text
            cmd.CommandText = sql
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            connections.Close()
            MsgBox("Data Hasbeen saved !", vbInformation)
        Catch ex As Exception
            MsgBox("Error when saving data !" & ex.Message)
        End Try
    End Sub
    Private Sub MetroButton2_Click(sender As Object, e As EventArgs) Handles MetroButton2.Click
        Dim savaedata As String
        Dim massege As String
        If NewData Then
            massege = MsgBox("Are you sure to add new data to database?", vbYesNo + vbInformation, "Information")
            If massege = vbNo Then
                Exit Sub
            End If
            savaedata = "INSERT INTO karyawan(id_karyawan,nama_karyawan,nik,jabatan,no_telphone,alamat) " _
            + "Values('" & MetroTextBox1.Text & "','" & MetroTextBox2.Text & "','" & MetroTextBox3.Text & "','" & MetroTextBox4.Text & "','" & MetroTextBox5.Text & "','" & MetroTextBox6.Text & "')"
        Else
            massege = MsgBox("Are you sure to UPDATE data to database?", vbYesNo + vbInformation, "Information")
            If massege = vbNo Then
                Exit Sub
            End If
            savaedata = "UPDATE karyawan SET nama_karyawan='" & MetroTextBox2.Text & "' " _
            + ",nik='" & MetroTextBox3.Text & "' " _
            + ",jabatan='" & MetroTextBox4.Text & "' " _
            + ",no_telphone='" & MetroTextBox5.Text & "' " _
            + ",alamat='" & MetroTextBox6.Text & "' where id_karyawan='" & MetroTextBox1.Text & "'"
        End If
        RunSQL(savaedata)
        MetroGrid1.Refresh()
        LoadData() ' insert data again after you update the data
    End Sub
    Private Sub MetroButton3_Click(sender As Object, e As EventArgs) Handles MetroButton3.Click
        Dim delete As String
        Dim message As String
        message = MsgBox("Are you sure want to delete this data?  ", vbExclamation + vbYesNo, "warning")
        If message = vbNo Then Exit Sub
        delete = "DELETE from karyawan where id_karyawan='" & MetroTextBox1.Text & "'"
        RunSQL(delete) ' delet functions
        MetroGrid1.Refresh()
        LoadData() ' insert data again after you update the data
    End Sub
    Private Sub MetroButton4_Click(sender As Object, e As EventArgs) Handles MetroButton4.Click
        Me.Close()
    End Sub
End Class
If  you are still confused by the tutorial above, just follow step by step this video, i have create a video CRUD tutorial just for you, hope you enjoyed.

Video Tutorial CRUD Operations with MySQL Database (English Version)

Download Source Code Project CRUD with MySQL Database
Download MySQL Database VB.NET CRUD

Please ask any questions in the comments box below, I would be very glad if can help you and don't forget to follow us in Social media. thanks before.

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: VB.NET Insert Update Delete with MySQL Database Metro UI Theme + Source Code
VB.NET Insert Update Delete with MySQL Database Metro UI Theme + Source Code
VB.NET For beginner : how toCRUD operations (insert,read,update,delete) in vb.net with mysql database and Metro theme UI windows Form? download source code simple CRUD applications in sector code.
https://3.bp.blogspot.com/-xaKEFl8Eiys/Vz9S1is45HI/AAAAAAAABvQ/P0aWZN5IECk_cS9KY0QKk5rUhIMWPJJKwCLcB/s320/crud-operations-vb-net.jpg
https://3.bp.blogspot.com/-xaKEFl8Eiys/Vz9S1is45HI/AAAAAAAABvQ/P0aWZN5IECk_cS9KY0QKk5rUhIMWPJJKwCLcB/s72-c/crud-operations-vb-net.jpg
KODE AJAIB
https://www.kodeajaib.com/2016/05/vbnet-insert-update-delete-with-mysql.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/05/vbnet-insert-update-delete-with-mysql.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy