Imports System.Data.SqlClient Imports System.IO Public Class SqlCon Public sql As SqlConnection Public str As String = "" Public Sub sqlOpen() str = StringConex() sql = New SqlConnection(str) sql.Open() End Sub Public Sub sqlClose() sql.Close() sql.Dispose() End Sub Public Function StringConex() As String Dim rd As New StreamReader("conex.txt") Dim linea As String = rd.ReadLine() rd.Close() rd.Dispose() Return linea End Function End Class Public Class Form1 Private Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click Dim con As New SqlCon Try con.sqlOpen() MessageBox.Show("Conexión OK!") con.sqlClose() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub End Class
miércoles, 25 de enero de 2017
Conectar sql en una clase separada
Suscribirse a:
Comentarios de la entrada (Atom)
No hay comentarios.:
Publicar un comentario