@producto nvarchar(40) as select * from dbo.Productos where NombreProducto= @producto
DENTRO DE BOTON CONSULTAR
Try Dim cn As New SqlConnection Dim cmd As SqlCommand Dim ds As New DataSet 'por cada select se tendra un adaptador Dim adapcateg As New SqlDataAdapter Dim adapprod As New SqlDataAdapter cn.ConnectionString = conecta cmd = New SqlCommand cmd.CommandText = "select IdCategora,NombreCategora,Descripcin from Categoras" cmd.CommandType = CommandType.Text cmd.Connection = cn adapcateg.SelectCommand = cmd adapcateg.Fill(ds, "Categoras") '--------------------------------------------------cmd = New SqlCommand cmd.CommandText = "select * from Productos" cmd.CommandType = CommandType.Text cmd.Connection = cn adapprod.SelectCommand = cmd adapprod.Fill(ds, "Productos") '------------------------Dim parentcol As New DataColumn
Dim childcol As New DataColumn
parentcol = ds.Tables("Categoras").Columns("IdCategora") childcol = ds.Tables("Productos").Columns("IdCategora") Dim relcustorder As DataRelation relcustorder = New DataRelation("CategoraProductos", parentcol, childcol) ds.Relations.Add(relcustorder) Dim filapadre, filahijo As DataRow Dim nodo, nodohijo As TreeNode For Each filapadre In ds.Tables(0).Rows nodo = New TreeNode nodo.Text = filapadre.Item(1) nodo.ImageIndex = 0 Me.TreeView1.Nodes.Add(nodo) For Each filahijo In filapadre.GetChildRows("CategoraProductos") nodohijo = New TreeNode nodohijo.Text = filahijo.Item(1) nodohijo.ImageIndex = 1 nodo.Nodes.Add(nodohijo) Next Next Catch ex As Exception MessageBox.Show(ex.Message) End Try
DENTRO DE TREEVIEW My.Forms.Formostrar.Show()
CREACION DE SEGUNDO FORMULARIO
DENTRO DEL LOAD DEL FORMULARIO
Try Dim cnn As New SqlConnection
Dim comando As New SqlCommand
Dim lector As SqlDataReader Dim fila As ListViewItem Dim prod As String prod = My.Forms.Form1.TreeView1.SelectedNode.Text cnn.ConnectionString = conecta cnn.Open() comando.CommandText = "Pa_mostrar" comando.CommandType = CommandType.StoredProcedure comando.Parameters.Add("@producto", SqlDbType.NVarChar, 40).Value = My.Forms.Form1.TreeView1.SelectedNode.Text.Trim comando.Connection = cnn Me.ListView1.Items.Clear() lector = comando.ExecuteReader If lector.HasRows = True Then While lector.Read fila = New ListViewItem fila.Text = CStr(lector.Item(0)) fila.SubItems.Add(CStr(lector.Item(1))) fila.SubItems.Add(CStr(lector.Item(2))) fila.SubItems.Add(CStr(lector.Item(3))) fila.SubItems.Add(CStr(lector.Item(4))) fila.SubItems.Add(CStr(lector.Item(5))) fila.SubItems.Add(CStr(lector.Item(6))) fila.SubItems.Add(CStr(lector.Item(7))) Me.ListView1.Items.Add(fila) End While End If lector.Close() cnn.Dispose() cnn.Close() Catch ex As Exception 'mostrar un mensaje cuando ocurre un error MessageBox.Show(ex.Message) End Try