VB 2013 - Database SQL Server Connection

10:39:00 PM
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
        OpenDB()
        da = New SqlDataAdapter("Select * from TBL_PRODUCT", Conn)
        ds = New DataSet
        ds.Clear()
        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 :)

Artikel Terkait

Next Article
« Prev Post
Previous Article
Next Post »
Penulisan markup di komentar
  • Untuk menulis huruf bold silahkan gunakan <strong></strong> atau <b></b>.
  • Untuk menulis huruf italic silahkan gunakan <em></em> atau <i></i>.
  • Untuk menulis huruf underline silahkan gunakan <u></u>.
  • Untuk menulis huruf strikethrought silahkan gunakan <strike></strike>.
  • Untuk menulis kode HTML silahkan gunakan <code></code> atau <pre></pre> atau <pre><code></code></pre>, dan silahkan parse dulu kodenya pada kotak parser di bawah ini.
Konversi Code
Disqus
Silahkan Berkomentar Dengan