VB 2013 - Database SQL Server Connection

In This tutorial I will share about How to connect database SQL Server in VB NET 2013. There are three step to connected Database SQL Server :
  • Step 1: Create New Project use VB 2013
  • Step 2 :Create database and table in MS Access 2003
  • Step 3 : Design form in VB .Net 2013

Step : 1
Click Visual Studio 2013

Click FILE - New - Project..
after that like below picture :
Click OK
After that, please follow STEP 2

Step 2 :
Create Database and Table in SQL Server
Please create database with name : DB_MYAPP
Create Table with name : TBL_PRODUCT
Fill data for sample in TBL_PRODUCT
 #Step 3 :
Design form1 like below picture
Just add "Datagridview1" in Form1

Place below code at Form1
Imports System.Data.SqlClient
Public Class Form1
    Dim Conn As SqlConnection
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim DBLocation As String
    Sub OpenDB()
        DBLocation = "data source=COMPUTERNAME;initial catalog=DB_MYAPP;integrated security =true"
        Conn = New SqlConnection(DBLocation)
        If Conn.State = ConnectionState.Closed Then Conn.Open()
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        da = New SqlDataAdapter("Select * from TBL_PRODUCT", Conn)
        ds = New DataSet
        da.Fill(ds, "TBL_PRODUCT")
        DataGridView1.DataSource = (ds.Tables("TBL_PRODUCT"))
    End Sub
End Class
Here for the result :
Is it easy??? Thank you for visiting Blog BelajarVB and Stay tuned for our next lesson :)

Subscribe to receive free email updates:

0 Response to "VB 2013 - Database SQL Server Connection"

Post a Comment