How to write function in to connect to MySQL Server Database

1. General Concepts:

There are a lot of database engine to store data table such as MySQL Server, Microsoft SQL Server, SQLLite, etc. Those are working as the RDBMS which is stand for Relational Database Management System. So How to connect from Programming to MySQL Server Database? As the programs seem to be separated from each other due to the difference companies. or Visual Basic Dot Net comes Microsoft Company whist MySQL Server might come from various sources of various companies. Therefore, in order to connect from to MySQL Server Database, please kindly visit to our previous tutorials Database Connection using programming, you can either download the .DLL file library and start step by step to install it and connect and MySQL Server Database.

2. Software Requirement

To work with this tutorials, you need to have:

  1. Microsoft Visual Studio 2015 up to latest version
  2. WAMP Server or XAMPP Server ( these two software contain automatic MySQL Server Database)

    After the installation of WAMP Server, you will see the phpmyadmin in Tools after that click on that then you will see as the following photos

      By Default from MySQL Server Database, Username must be root and Password must be blanked. Server Choice, you can either select MySQL or MariaDB.

      3. Tutorials

      STEP 1: Going to MySQL Database, then create a database. Name it as houserentings. In MySQL Database, please Select on Database then name it and click on Create

        STEP 2: Go to Microsoft Visual Studio the Create a project. In your project, please create a new form

          Then Click on OK. After click on Ok, you can go to Form1 and them implement the code as below:

          Imports MySql.Data.MySqlClient
          Public cn As New MySqlConnection
              Dim cm As New MySqlCommand
              Dim result As Boolean
              Dim conString As String
              Dim sql As String
              Public Function OpenDB() As Boolean
                      If cn.State = ConnectionState.Closed Then
                          conString = "server=localhost;user=root;password=;database=houserenting"
                          cn.ConnectionString = conString
                          result = True
                          MsgBox("Connection Successfully", vbInformation)
                      End If
                  Catch ex As Exception
                      result = False
                  End Try
                  Return result
              End Function

          on the Header of the Form, please include Imports MySql.Data.MySqlClient. Then go to your Form1, on the Form_Load Event, please write the code below:

          Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
              End Sub

          The result from the compiling: