This lesson will focus on Setting Database Connection for Managing the Payroll System Module statement defines a reference type available throughout its namespace. In this case, we set a standard module which is similar to a class but with some important distinctions.
Every module has exactly one instance and does not need to be created or assigned to a variable. According to MSDN, Modules do not support inheritance or implement interfaces. Notice that a module is not a type in the sense that a class or structure is — you cannot declare a programming element to have the data type of a module.
Setting Database Connection
First, we have to add a reference to our project which is the MySql.Data.dll. See figure below to see the picture of it. If this time to do this, you may also search other tutorials here for the procedure on how to add MySql reference.
The code below shows how to connect our Payroll System to our database. Reviewing our lesson 3 which is Database Design in MySQL for Payroll System using XAMPP 1.7.4 Server Application our database is PayrollDatabase.
Dim MysqlConn As New MySqlConnection
Public Function myconn() As MySqlConnection
Return New MySqlConnection(“server=localhost;user id=root;password=;database=PayrollDatabase”)
There are 3 important parts to be considered. First is the Imports statement which enables types that are contained in a given namespace to be referenced directly. Second is the declaration of MysqlConn variable as a new MySqlConnection. And lastly, the public function myconn as MySqlconnection that performs a task and then returns control to the calling code. When it returns control, it also returns a value to the calling code.
If you have any questions or suggestion about Setting Database Connection, Please feel free to contact me at our contact page. Or, you can review this topic on How to Create MySQL Connection Using VB.Net.