Emml Anim Emml Anim - 6 months ago 22
MySQL Question

Insert, update and delete

I have created a database with MySQL server management studio and I want to connect it to Vb.net in visual basic to enable me insert, update and delete information

sam sam
Answer

Hope this helps.

Imports MySql.Data.MySqlClient

Module mdlDataConn
Public conn As New MySqlConnection

Public Sub ConnectDatabase()

    Try
        If conn.State = ConnectionState.Closed Then
            conn.ConnectionString = "DATABASE=" & My.Settings.myDB & ";" _
              & "SERVER=" & My.Settings.myServer & ";user id=" & My.Settings.myUsername _
              & ";password=" & My.Settings.myPassword &";port=" & _
              My.Settings.myPort & ";charset=utf8"
            conn.Open()
        End If

    Catch myerror As Exception
        MessageBox.Show("Error Connecting to the database", "Error Database Server", _
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End
    End Try
End Sub

Public Sub DisconnectDatabase()
    Try
        conn.Close()
    Catch myerror As MySql.Data.MySqlClient.MySqlException

    End Try
End Sub
End Module
'To connect to mySQL Database just call.
ConnectDatabase

'To close the mySQL Database
DisconnectDatabase
Comments