본문 바로가기
Programing/vb.net

visual basic,비주얼베이직,vb .net 강좌-ms sql 접속테스트,SqlConnection ,SqlCommand,conntect Text,

by 고니의 경제주식 2017. 2. 2.
반응형


'Form1.vb


Public Class Form1

    Dim SQL As New SQLControl

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        If SQL.HasConection = True Then


            MessageBox.Show("seccesfully connected")

        End If


    End Sub

End Class


'SQLControl.vb 


Imports System.Data.Sql

Imports System.Data.SqlClient



Public Class SQLControl

    Public SQLCon As New SqlConnection With {.ConnectionString = "Server=MSDN-SPECIAL\SQLEXPRESS;Database=test;User=sa;Pwd=1111;"}

    Public SQLCmd As SqlCommand

    Public Function HasConection() As Boolean

        Try

            SQLCon.Open()

            SQLCon.Close()

            Return True


        Catch ex As Exception

            MessageBox.Show(ex.Message)

            Return False


        End Try

    End Function


End Class





반응형