holas yo lo tutilizo asi espero y te sirva cualquier duda por aqui andamos
[email protected] asunto: Foros del Web
hay coneccion para sql y accsses y formas de utilizar la coneccion.....
Imports System.Data
Imports System.Data.SqlClient
Public Class IntegraLibrary
Private Function GetConnectionString(ByVal _usuario As String, ByVal _password As String) 'con la autenticacion de SQLServer
Dim _servidor As String = "desarrollo1"
Dim _DB As String = "KBW"
Return String.Format("Server={0};Database={1};User Id={2};Password={3};", _servidor, _DB, _usuario, _password)
End Function
Private Function GetConnectionString() '' para uso de autenticació con la informacion de la cuenta de windows del usuario conectado
Dim _servidor As String = "DESARROLLO1"
Dim _DB As String = "INTEGRA"
Dim _ISecurity As String = "SSPI"
Return String.Format("Server={0};Database={1};Integrated Security={2}", _servidor, _DB, _ISecurity)
End Function
Private Function GetConnectionStringAccess() '' para uso de autenticació con la informacion de la cuenta de windows del usuario conectado
Dim _servidor As String = "DESARROLLO1"
Dim _DB As String = "INTEGRA"
Dim _ISecurity As String = "SSPI"
Return String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", _DB)
End Function
Public Sub exeQry(ByVal strQry As String, ByVal LBL As Label)
Dim myCnn As SqlConnection = New SqlConnection(GetConnectionString())
Dim cmd As SqlCommand = New SqlCommand(strQry, myCnn)
Dim Update As String
Try
myCnn.Open()
cmd.ExecuteNonQuery()
LBL.Text = "OPERACIÓN REALIZADA SATISFACTORIAMENTE" 'strQry.ToString 'Update.ToString
myCnn.Close()
myCnn = Nothing
cmd = Nothing
Catch ex As Exception
LBL.Text = ex.Message
End Try
End Sub
Public Function exeQry(ByVal strQry As String)
Dim myCnn As SqlConnection = New SqlConnection(GetConnectionString())
Dim cmd As SqlCommand = New SqlCommand(strQry, myCnn)
Dim Update As String
Try
myCnn.Open()
cmd.ExecuteNonQuery()
Update = "OPERACIÓN REALIZADA SATISFACTORIAMENTE" 'strQry.ToString 'Update.ToString
myCnn.Close()
myCnn = Nothing
cmd = Nothing
Catch ex As Exception
Update = ex.Message
myCnn.Close()
myCnn = Nothing
cmd = Nothing
End Try
Return Update
End Function
Public Function getDataTable(ByVal strQry As String)
Dim myCnn As SqlConnection = New SqlConnection(GetConnectionString())
Dim dt As New DataTable
Dim qry As SqlCommand = New SqlCommand(strQry, myCnn)
myCnn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(qry)
da.Fill(dt)
Return dt
myCnn.Close()
myCnn = Nothing
da = Nothing
'dr = Nothing
End Function
saludos rahdRR....