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

.,, - ,, - , , - and - and - : Return

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)
22 views3 pages

.,, - ,, - , , - and - and - : Return

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
You are on page 1/ 3

Create Procedure Sp_ConsultaOrden

@Orden Int
As
Select
Orders.OrderID,ProductName,[Order Details].UnitPrice as Precio,
Quantity as Cantidad, [Order Details].UnitPrice * Quantity as Subtotal
From [Order Details],Products,Orders
where [Order Details].ProductID=Products.ProductID
and Orders.OrderId=[Order Details].OrderID
and Orders.OrderID=@Orden
Return
go
Create Procedure Sp_ConsultaFecha
@FechaIni Varchar(20),
@FechaFin Varchar(20)
As
Select
Orders.OrderID,ProductName,[Order Details].UnitPrice as Precio,
Quantity as Cantidad,[Order Details].UnitPrice * Quantity as Subtotal
From [Order Details],Products,Orders
where [Order Details].ProductID=Products.ProductID
and Orders.OrderId=[Order Details].OrderID
and OrderDate Between @FechaIni and @FechaFin
Return
Go
Codigo para el formulario
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
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 System.Object, ByVal e As System.EventArgs) Handles Ok.Click
If RbnOrden.Checked Then
Dim objCommand As New SqlClient.SqlCommand("Sp_ConsultaOrden")

objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Clear()
objDataSet.Clear()
objCommand.Parameters.Add("@Orden", SqlDbType.Int, 10)
objCommand.Parameters("@Orden").Value = Val(TxtOrden.Text)
objCommand.Connection = New SqlClient.SqlConnection(Conexion)
objCommand.Connection.Open()
Dim objAdapter As New SqlDataAdapter(objCommand)
objAdapter.Fill(objDataSet)
objCommand.Connection.Close()
DataGrid1.DataSource = objDataSet.Tables(0)
End If
If RbnFecha.Checked Then
Dim objCommand As New SqlClient.SqlCommand("Sp_ConsultaFecha")
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Clear()
objDataSet.Clear()
objCommand.Parameters.Add("@FechaIni", SqlDbType.VarChar, 15)
objCommand.Parameters("@FechaIni").Value = TxtFe1.Text
objCommand.Parameters.Add("@FechaFin", SqlDbType.VarChar, 15)
objCommand.Parameters("@FechaFin").Value = TxtFe2.Text
objCommand.Connection = New SqlClient.SqlConnection(Conexion)
objCommand.Connection.Open()
Dim objAdapter As New SqlDataAdapter(objCommand)
objAdapter.Fill(objDataSet)
objCommand.Connection.Close()
DataGrid1.DataSource = objDataSet.Tables(0)
End If
End Sub
End Class

You might also like