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

SQL Stored Procedures for Order Queries

The document defines two stored procedures - Sp_ConsultaOrden and Sp_ConsultaFecha - to retrieve order details from a database based on an order ID or date range. It also includes code for a form that calls the stored procedures and displays the results in a datagrid, allowing the user to search by order or date. Sp_ConsultaOrden selects order details matching a supplied order ID, while Sp_ConsultaFecha selects order details between a from and to date provided as parameters. The form code handles button clicks, clears datasets, opens connections, executes the appropriate stored procedure based on radio button selection, fills the dataset, and binds it to the datagrid control for display.

Uploaded by

Eliza H. Aguilar
Copyright
© © All Rights Reserved
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)
6 views3 pages

SQL Stored Procedures for Order Queries

The document defines two stored procedures - Sp_ConsultaOrden and Sp_ConsultaFecha - to retrieve order details from a database based on an order ID or date range. It also includes code for a form that calls the stored procedures and displays the results in a datagrid, allowing the user to search by order or date. Sp_ConsultaOrden selects order details matching a supplied order ID, while Sp_ConsultaFecha selects order details between a from and to date provided as parameters. The form code handles button clicks, clears datasets, opens connections, executes the appropriate stored procedure based on radio button selection, fills the dataset, and binds it to the datagrid control for display.

Uploaded by

Eliza H. Aguilar
Copyright
© © All Rights Reserved
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

Create Procedure Sp_ConsultaOrden

@Orden Int
As
Select
[Link],ProductName,[Order Details].UnitPrice as Precio,
Quantity as Cantidad, [Order Details].UnitPrice * Quantity as Subtotal
From [Order Details],Products,Orders
where [Order Details].ProductID=[Link]
and [Link]=[Order Details].OrderID
and [Link]=@Orden
Return
go
Create Procedure Sp_ConsultaFecha
@FechaIni Varchar(20),
@FechaFin Varchar(20)
As
Select
[Link],ProductName,[Order Details].UnitPrice as Precio,
Quantity as Cantidad,[Order Details].UnitPrice * Quantity as Subtotal
From [Order Details],Products,Orders
where [Order Details].ProductID=[Link]
and [Link]=[Order Details].OrderID
and OrderDate Between @FechaIni and @FechaFin
Return
Go
Codigo para el formulario
Imports [Link]
Imports [Link]
Imports [Link]
Public Class Form1
Public Conexion As String = "Data Source=UPEA_A27;Initial Catalog=NorthWind;User Id = SA;Password=123;"
Public objDataSet As New DataSet()
Private Sub Ok_Click(ByVal sender As [Link], ByVal e As [Link]) Handles [Link]
If [Link] Then
Dim objCommand As New [Link]("Sp_ConsultaOrden")

[Link] = [Link]
[Link]()
[Link]()
[Link]("@Orden", [Link], 10)
[Link]("@Orden").Value = Val([Link])
[Link] = New [Link](Conexion)
[Link]()
Dim objAdapter As New SqlDataAdapter(objCommand)
[Link](objDataSet)
[Link]()
[Link] = [Link](0)
End If
If [Link] Then
Dim objCommand As New [Link]("Sp_ConsultaFecha")
[Link] = [Link]
[Link]()
[Link]()
[Link]("@FechaIni", [Link], 15)
[Link]("@FechaIni").Value = [Link]
[Link]("@FechaFin", [Link], 15)
[Link]("@FechaFin").Value = [Link]
[Link] = New [Link](Conexion)
[Link]()
Dim objAdapter As New SqlDataAdapter(objCommand)
[Link](objDataSet)
[Link]()
[Link] = [Link](0)
End If
End Sub
End Class

You might also like