VB .Net 2017 Koneksi Database MySQL,Ms SQL Server, PostgreSQL and Ms Access
![]() |
VB .Net 2017 Koneksi Database MySQL,Ms SQL Server, PostgreSQL and Ms Access |
Tutorial Koneksi Visual Basic 2017 dengan 4 database, Databaes MySQL, Database Microsoft SQL Server Express 2014, Database Microsoft Acces dan Database PostgreSQL. Untuk koneksi ke MySQL menggunakan MySQL Connetor .Net, Microsoft Acces menggunakan OLEDB, Micorosoft SQL Server menggunakan SQLClient sedangkan untuk PostgreSQL menggunakan NpgSQL.Tutorial dibagi menjadi 2 bagian yaitu berupa file koneksi dan video tutorial agar lebih memahami. Jika ada yang kurang paham silahkan dikomentari.
Kode Form1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click | |
DBConn_Accdb() | |
End Sub | |
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click | |
DBConn_MsSQL() | |
End Sub | |
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click | |
DBConn_MySQL() | |
End Sub | |
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click | |
DBConn_PgSQL() | |
End Sub | |
End Class |
File Koneksi VB 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Data.OleDb | |
Imports System.Data.SqlClient | |
Imports MySql.Data.MySqlClient | |
Imports Npgsql | |
Module Connection | |
Dim db_string As String | |
Dim Conn1 As OleDbConnection '' Access DB | |
Dim Conn2 As SqlConnection '' Ms SQL Server | |
Dim Conn3 As MySqlConnection '' Mysql | |
Dim Conn4 As NpgsqlConnection '' PostgreSQL | |
Sub DBConn_Accdb() '' Connection For Access DB | |
db_string = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Net\tarman.accdb;" | |
Conn1 = New OleDbConnection(db_string) | |
Try | |
Conn1.Open() | |
MsgBox("DB Access Success") | |
Catch ex As OleDbException | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
Sub DBConn_MsSQL() ''COnnection For Ms SQL Server | |
db_string = "Data Source=WJT-01\SQLEXPRESS;Initial Catalog=customer;User ID=sa;Password=12345;" | |
Conn2 = New SqlConnection(db_string) | |
Try | |
Conn2.Open() | |
MsgBox("Ms SQL Server Success") | |
Catch ex As SqlException | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
Sub DBConn_MySQL() | |
db_string = "server=localhost;user=root;password=yourpassword;port=3307;database=ma star;" | |
Conn3 = New MySqlConnection(db_string) | |
Try | |
Conn3.Open() | |
MsgBox("MySQL Success") | |
Catch ex As MySqlException | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
Sub DBConn_PgSQL() | |
db_string = "Server=localhost;Port=5432;Database=customer;username=postgres;password=wishimajaya" | |
Conn4 = New NpgsqlConnection(db_string) | |
Try | |
Conn4.Open() | |
MsgBox("PostgreSQL Succes") | |
Catch ex As NpgsqlException | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
End Module |
Post a Comment
Post a Comment