Visual Basic.NET - recibir output de sql en vb.net

 
Vista:
sin imagen de perfil
Val: 50
Ha disminuido su posición en 2 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

recibir output de sql en vb.net

Publicado por Agustin (29 intervenciones) el 22/06/2020 15:09:38
buen día resulta que tengo un procedimiento que tiene una serie de parametros y por ultimo un output...

no se como ejecutar ese pr con un parametro output desde vb.net y q me devuelva el resultado en una caja de texto... les muestro como lo tengo hasta ahora

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Public Function CalculaPrecio(CODPROD As String, CUENTACLIENTE As String, DTOGRAL As Decimal, DESCUENTO As Decimal, PRECIO As Decimal, LISTADEPRECIO As Integer) As OleDbDataReader
 
    Dim myReader As OleDbDataReader
 
    Try
        Dim connexio As New OleDbConnection
        Dim myCommand As New OleDbCommand
        Dim campo As String
 
        connexio = New OleDbConnection(myConnectionString)
        myCommand.CommandText = ("CalculaPrecio")
        myCommand.CommandType = CommandType.StoredProcedure
        myCommand.Connection = connexio
        myCommand.Parameters.AddWithValue("@CODPROD", CODPROD)
        myCommand.Parameters.AddWithValue("@CUENTACLIENTE", CUENTACLIENTE)
        myCommand.Parameters.AddWithValue("@DTOGRAL", DTOGRAL)
        myCommand.Parameters.AddWithValue("@DESCUENTO", DESCUENTO)
        myCommand.Parameters.AddWithValue("@PRECIO", PRECIO)
        myCommand.Parameters.AddWithValue("@LISTADEPRECIO", LISTADEPRECIO)
        myCommand.Parameters("@PRECIOFINAL").Direction = ParameterDirection.Output
 
        connexio.Open()
 
        myReader = myCommand.ExecuteReader()
 
        Dim PRECIOFINAL As Decimal = CInt(myCommand.Parameters("@PRECIOFINAL").Value)
 
        Return myReader
    Catch exc As Exception
        MsgBox("Error: " & exc.Message)
        Return myReader
    End Try
 
End Function

despues en el form donde llamo a ese parametro hago lo siguiente:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Public Sub CalculaPrecio(CODPROD As String, CUENTACLIENTE As String, DTOGRAL As Decimal, DESCUENTO As Decimal, PRECIO As Decimal, LISTADEPRECIO As Integer)
    Dim objStreamWriter As StreamWriter
    Dim path As String
 
    Windows.Forms.Application.DoEvents()
 
 
    Dim myReader As OleDbDataReader
    myReader = Data.CalculaPrecio(CODPROD, CUENTACLIENTE, DTOGRAL, DESCUENTO, PRECIO, LISTADEPRECIO)
 
    Me.Refresh()
    Windows.Forms.Application.DoEvents()
 
    path = System.Windows.Forms.Application.StartupPath
End Sub

y en el evento click del boton llamo a ese public sub y le paso los valores

1
CalculaPrecio(txtCodProd.Text, txtClienteCuenta.Text, txtDescGral.Text, txtDescuento.Text, txtPrecio.Text, txtListaPrecio.Text)


la verdad que no se como hacer...

agradezco mucho su ayuda. saludos!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 50
Ha disminuido su posición en 2 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

recibir output de sql en vb.net

Publicado por Agustin (29 intervenciones) el 23/06/2020 03:05:30
ya lo solucione de la siguiente forma

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Dim myReader As OleDbDataReader
 
Try
    Dim connexio As New OleDbConnection
    Dim myCommand As New OleDbCommand
    Dim PRECIOFINAL As Decimal
 
    connexio = New OleDbConnection(myConnectionString)
    myCommand.CommandText = ("CalculaPrecio")
    myCommand.CommandType = CommandType.StoredProcedure
    myCommand.Connection = connexio
    myCommand.Parameters.AddWithValue("@CODPROD", CODPROD)
    myCommand.Parameters.AddWithValue("@CUENTACLIENTE", CUENTACLIENTE)
    myCommand.Parameters.AddWithValue("@DTOGRAL", DTOGRAL)
    myCommand.Parameters.AddWithValue("@DESCUENTO", DESCUENTO)
    myCommand.Parameters.AddWithValue("@PRECIO", PRECIO)
    myCommand.Parameters.AddWithValue("@LISTADEPRECIO", LISTADEPRECIO)
    myCommand.Parameters.Add("@PRECIOFINAL", SqlDbType.Decimal)
    myCommand.Parameters("@PRECIOFINAL").Direction = ParameterDirection.Output
 
    connexio.Open()
 
    myReader = myCommand.ExecuteScalar()
 
    PRECIOFINAL = myCommand.Parameters("@PRECIOFINAL").Value
    frmAgregaRemito.txtPrecioFinal.Text = PRECIOFINAL


sin embargo tengo otro problema... me tira el valor entero no con decimales
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Wilfredo Patricio Castillo
Val: 1.239
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

recibir output de sql en vb.net

Publicado por Wilfredo Patricio Castillo (720 intervenciones) el 23/06/2020 03:13:22
A ver Agustín.

Primero hay que tener bien claro lo que se está haciendo, si no tenemos idea de qué estamos haciendo los problemas se nos harán inmensos e interminables.

Entonces partiendo desde esa premisa veamos.

Que es lo que pretendes obtener?, Si me dices, el PRECIOFINAL, porque para eso es el parámetro output, para devolver un valor desde el storeprocedure, siendo eso cierto, cuál sería el motivo de devolver un datareader?, acaso lo vas a recorrrer o algo?, no verdad?, solo devuelve el PRECIOFINAL.

Finalmente si ya capturas el PRECIOFINAL, en la variable del mismo nombre solo tendría que devolver(return) PRECIOFINAL Y LISTO, ahora, nuevamente insisto.

Si PRECIOFINAL, es una variable de tipo Decimal, cuál es el motivo de convertir el valor que obtienes en el parámetro de salida que asumo que es un decimal, a Integer?, osea porque convertir un decimal a Entero para asignarlo a Decimal?, te das cuenta que estás programando a propósito mas errores?.

Tendrías que convertir a Decimal y asignarlo y listo, retornar preciofinal, y asunto arreglado, y la cosa sería suoer sencilla.

Saludos cordiales,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar