SoloCodigo
CLR: .Net / Mono / Boo / Otros CLR => VB .NET => Mensaje iniciado por: happypeace31 en Viernes 4 de Septiembre de 2009, 13:44
-
holas a todos!!
Necesito saber como conectar una base de SQL en visual .net pero a traves del codigo
Le agradesco su ayuda :P
Espero me puedan ayudar gracias :beer:
-
Espero te sirva.
Imports System.Data.SqlClient
Private CN As SqlConnection
Private DA As New SqlDataAdapter
' Con esto te conectas
Private Function Conectar(ByVal DA As SqlDataAdapter) As SqlDataAdapter
'Crear conexión
CN = New SqlConnection
Try
CN.ConnectionString = "Server=(local);" & "Database=BlackBox;uid=sa;pwd=sa;Integrated Security=SSPI;"
Catch ex As ArgumentException
MsgBox("Error:" & vbCrLf & "ConnectionString", MsgBoxStyle.Critical)
End Try
DA = New SqlDataAdapter
Return DA
End Function
'Una funcion para que ocupes la coneccion
Public Function Proveedor_Tabla() As DataSet
Conectar(DA)
DA.SelectCommand = New SqlCommand
DA.SelectCommand.Connection = CN
DA.SelectCommand.CommandText = "sp_TablaProveedores"
DA.SelectCommand.CommandType = CommandType.StoredProcedure
DS = New DataSet
DA.Fill(DS, "Proveedores")
DT = DS.Tables("Proveedores")
Return DS
End Function
-
gracias por tu aporte me fue de gran ayuda :beer: