0% found this document useful (0 votes)
35 views1 page

Visual Net

This code shows how to connect a SQL database to a Visual Basic application and retrieve data from tables to populate controls. It opens a connection to a SQL Server database called Northwind, selects data from the Categories table to populate a combo box, then selects related data from the Products table to display in a grid based on the selected category. When the category selection changes, it filters the products grid to only show items for that category.

Uploaded by

Johanna CG
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 DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Visual Net

This code shows how to connect a SQL database to a Visual Basic application and retrieve data from tables to populate controls. It opens a connection to a SQL Server database called Northwind, selects data from the Categories table to populate a combo box, then selects related data from the Products table to display in a grid based on the selected category. When the category selection changes, it filters the products grid to only show items for that category.

Uploaded by

Johanna CG
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 DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Cdigo para conexin de base de datos Sql con Visual Imports System.Data Imports System.Data.

SqlClient Public Class frmProducto Private Cno As New SqlConnection("User id=sa;server=.;Database=Northwind") ....( coneccion, usuario y contrasea ,nombre de la base de datos) Private Dap As New SqlDataAdapter("Select CategoryId,CategoryName From Categories", Cno) ....(tabla nombre de la tabla y seleccion a utilizar) Private dst As New DataSet Private Sub frmProducto_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dap.Fill(dst, "Categorias") ---(Dap data adapter) With cboCategoria .DataSource = dst.Tables("Categorias") .DisplayMember = "CategoryName" .ValueMember = "CategoryId" End With Dap.SelectCommand.CommandText = "Select ProductId,ProductName,CategoryId,UnitPrice,UnitsInStock From Products" Dap.Fill(dst, "Productos") grdProducto.DataSource = dst.Tables("Productos") dst.Tables("Productos").DefaultView.RowFilter = "CategoryId=" & cboCategoria.SelectedValue End Sub Private Sub cboCategoria_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCategoria.SelectedIndexChanged Try dst.Tables("Productos").DefaultView.RowFilter = "CategoryId=" & cboCategoria.SelectedValue Catch ex As Exception End Try End Sub End Class

You might also like