105 – Setting Database Connection for Managing Payroll System Module

0
203

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.

  1. Imports MySql.Data.MySqlClient
  2.  
  3. Module PayrollMod
  4.  
  5. Dim MysqlConn As New MySqlConnection
  6.  
  7. Public Function myconn() As MySqlConnection
  8. Return New MySqlConnection("server=localhost;user id=root;password=;database=PayrollDatabase")
  9. End Function
  10. End Module

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.

 

 

Facebook Comments
(Visited 222 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here