Connect Vb.Net To Sql Server Database

VB.NET - How To Connect Visual Basic .Net With SqlServer DataBase

                                                                                                                         

In This VB.NET Tutorial We Will See How To Connect And Disconnect From Microsoft SQL DataBase Using Visual Basic .NET Programming Language.


Project Source Code:

Imports System.Data.SqlClient

Public Class Connect_To_SQL

    Dim connection As New SqlConnection("Server= SAMSNG-PC; Database = TestDB; Integrated Security = true")

    Private Sub BTN_CONNECT_Click(sender As Object, e As EventArgs) Handles BTN_CONNECT.Click

        If connection.State = ConnectionState.Closed Then

            connection.Open()
            lbl_Conn.Text = "Connected"
            lbl_Conn.ForeColor = Color.Green


        End If

    End Sub

    Private Sub BTN_Disconnect_Click(sender As Object, e As EventArgs) Handles BTN_Disconnect.Click

        If connection.State = ConnectionState.Open Then

            connection.Close()
            lbl_Conn.Text = "DisConnected"
            lbl_Conn.ForeColor = Color.Red

        End If

    End Sub
End Class

///////////////OUTPUT:

connecting vb.net to sql server database







Share this

Related Posts

Previous
Next Post »