1. First Example.
First of all We have to have a database.
- Open your sql server then type the code that shown below :
- Type this codes :
create database contoh_1
use database contoh_1
create table contoh
(
id int identity(1,1),
keterangan varchar(20),
)
If you already written code above then press "F5" to create it.
- The database already created, now I will show you how to create the connection string in vb.net
1. Open Visual Studio 2012.
2. Create New Project -> Choose "Windows Form" then will display like image below.
3. After that you just need to press "F7" to show the codes area like image below
- Type This Codes :
Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim str As String = Nothing
Sub koneksiDB()
str = "data
source = INTERNOFATEAM\LENOVOSQL; database = contoh_1; user id = sa; password =
password_sql_anda"
con = New SqlConnection(str)
con.Open()
MsgBox("Koneksi
Berhasil Dibuka.", MsgBoxStyle.Information, "Informasi")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
koneksiDB()
End Sub
End Class
- After you type the code like above then you press "F5" to running the program, and if you made it the program will show you the message box like below.
- The First Ways to create the connection string already done, I will give you another example and project in the next section.
EmoticonEmoticon