Todo Conexioness
Todo Conexioness
Modulo conexin
Imports System.Data Imports System.Data.SqlClient Module Module2 Public cnx As New SqlConnection("server=.;database=Northwind;integrated security=true") End Module -----------------------------------------visual--------------------Imports System.Data Imports System.Data.SqlClient Public Class Form3 Dim dst As New DataSet Dim poscat As Integer Public cnx As New SqlConnection("server=.;database=Northwind;integrated security=true") Sub cargacategoria() TextBox1.Text = dst.Tables("categories").Rows(poscat).Item("CategoryID") TextBox2.Text = dst.Tables("categories").Rows(poscat).Item("CategoryName") TextBox3.Text = dst.Tables("categories").Rows(poscat).Item("Description") End Sub Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim da As New SqlDataAdapter("listarproducto", cnx) da.Fill(dst) dst.Tables(0).TableName = "Categories" cargacategoria() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If poscat < dst.Tables("categories").Rows.Count - 1 Then poscat = poscat + 1 End If cargacategoria() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If poscat > 0 Then poscat = poscat - 1 End If cargacategoria() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If poscat = dst.Tables("categoria").Rows.Count - 1 Then End If
cargacategoria() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click poscat = 0 cargacategoria() End Sub End Class
----------------------------------------- access --------------------------------------------Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim CNX As New OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=d:\ALMACEN.mdb") CNX.Open() MsgBox("conexion satisfactoria") Dim da As New OleDbDataAdapter("select* from Categoria", CNX) Dim dt As New DataTable da.fill(dt) Me.DataGridView1.DataSource = dt CNX.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim CNX As New OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=d:\ALMACEN.mdb") CNX.Open() MsgBox("conexion OK") Dim da As New OleDbDataAdapter("select * from Productos", CNX) Dim dt As New DataTable
--------------------- module----------------------Imports System.Data Imports System.Data.OleDb Module Module1 Public Sub conectar() ' Dim cnx As New OleDbConnection("Provider=Microsoft.jet.oledb .4.0;data Source=D\ALMACEN.mdb") End Sub End Module