Sunday 5 May 2019

Visual Basic 2012 connecting MySQL Database

In this Visual Guide, students will learn how to create a basic Windows Application integrating MySQL connection.

1. Open Visual Studio 2012.


2. Create a New Project. Templates Visual Basic then select Windows Forms Application. Framework by default is set to .Net Framework 4.5 . Type name for the Project. In this tutorial, vbnetmysql then click Ok button.




3. Add MySQL Data to Project References.  Click Project on the menu bar, then click vbnetmysql Properties.
Click References then click Add button.
Browse the location of the MySQL Connector we installed earlier.
Access C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.0 then click Ok button.
To confirm successfully, MySQL reference will be placed on top of other project references.
4. 😊 Save your windows application project. 
5. We need to start our MySQL server, in this tutorial XAMPP. Run the MySQL to establish a database connection.
Create database and tables. 
Database name: vbnetmysql
Table name: tbl_course (c_id int(11) primary key, c_name varchar(255) not null)



6. Add Module to your project.
Right click in your project name in Solution Explorer->Add then select Module

Type filename for it. dbconnect.vb then click Add button.



7. Type the following statement into your Module dbconnect.
     a.Type the statement above the line Module dbconnect
Imports MySql.Data.MySqlClient


    b. Declare Global Variables that will be accessible across your project. Type the following statements inside the Module dbconnect
Public dbconn As New MySqlConnection
Public sql As String
Public dbcomm As MySqlCommand
Public dbread As MySqlDataReader

       c. Create a Public Sub that will serve as a database connection script in the entire project. Type the following statement.
Public Sub mysql_connect()       
'Local Database
    dbconn = New MySqlConnection("Data Source=localhost;user id=root;database=vbnetmysql;")
    Try
       dbconn.Open()
       MsgBox("connected")
    Catch ex As Exception
       MsgBox("Error in connection, please check the database and connection server.", vbCritical, "System Demo Only")
       End
    End Try
End Sub
8. Test MySQL Connection in VB 2012
Open your Form1. Double click the form
then type mysql_connect() in Form1_Load
9. Run the program to confirm connection.
10. Connected successfully without hassle.

Visual Basic 2012 using MySQL Database Implementation

1. Installing MySQL Connector 6.9.8
2. Visual Basic 2012 Connecting MySQL Database
3. Adding Data to MySQL using Visual Basic 2012
4. Reading Data from Database in Visual Basic 2012 and MySQL 
5. Updating Data in Database in Visual Basic 2012 and MySQL

Please leave a comment if you think this article is helpful to your project. Thank you.

3 comments:

Nice nice niiiice. Tapos na sir 😂

thank you sir dire kuna kailangan pa magkita hin damo na tutorials...

An extremely helpful and informative tutorial page. 🌟🌟🌟🌟🌟

Post a Comment

If possible, leave a positive comment. No hate speech or elicit comments. Thank you.