Example : How to Connect VB .Net 2013 with SQL Server Database 2012
' Namespace for SQL Server 2012 Enterprise Edition

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlException
Imports System.IO
Imports System.Runtime.InteropServices  'Used when image capturing is taken directly from webcam.

Public Class Form1
    Dim cn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Dim cm As New SqlCommand
    Dim dt As New DataTable

    Dim rdr As SqlDataReader
    Dim bnd As BindingSource = New BindingSource()
    Dim cs As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cs = "Server= localhost; Database=databasename;Integrated Security=SSPI;"

        cn = New SqlConnection(cs)
        cm = New SqlCommand(cs, cn)
        da = New SqlDataAdapter("Select * from tablename", cs)
        ds = New DataSet
        da.Fill(ds, "tablename")

    End Sub
End Class

NB : Now click 'Tools' menu in VB .Net 2013 - click 'connect to database' option - choose 'Microsoft SQL Server' for Sql server enterprise edition and 'Microsoft SQL Server Database file' for Sql server express edition - click on 'continue' button - put MS Sql 'Server Name' - 'Select or enter a database name' in 'connect to database name' - Click on 'Test Connection' button - if connection succeeded, press ok.

 352 total views,  2 views today

Categories: VB .Net


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.