0% found this document useful (0 votes)
67 views3 pages

Todo Conexioness

The document discusses connecting to and retrieving data from both SQL Server and Microsoft Access databases in Visual Basic. It includes code snippets for establishing connections, executing queries, and loading data into datasets and datagrids. Modules and classes are defined for encapsulating the connection and data access logic. Buttons are used to navigate between records and load data from the databases into textboxes and grids on a form for viewing.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views3 pages

Todo Conexioness

The document discusses connecting to and retrieving data from both SQL Server and Microsoft Access databases in Visual Basic. It includes code snippets for establishing connections, executing queries, and loading data into datasets and datagrids. Modules and classes are defined for encapsulating the connection and data access logic. Buttons are used to navigate between records and load data from the databases into textboxes and grids on a form for viewing.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Visual

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

----------------------sql----------Esto trabaja con Northwind

alter proc listarproducto as select * from Categories go

----------------------------------------- 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

da.Fill(dt) Me.DataGridView1.DataSource = dt CNX.Close() End Sub

--------------------- 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

You might also like