Connect to SQL database with

Learn VB.Net Programming in simple and easy steps. tutorial for beginner.

How to connect SQL database using programming.

Establish a successful connection to a Microsoft SQL Server Database using

source code:

Imports System.Data.Sql
Imports System.Data.SqlClient

Public Class Form1
    Dim con As New SqlConnection
    Dim sql As String
    Dim ds As New DataSet
    Dim da As SqlDataAdapter

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = ("server=POS16-PC\SQLEXPRESS;database=aa;user=sa;pwd=100;")


        MsgBox("Database is now open")

        sql = "select * from student"
        da = New SqlDataAdapter(sql, con)

        da.Fill(ds, "test")

        DataGridView1.DataSource = ds.Tables("test")


        MsgBox("Database is now Closed")

    End Sub

End Class