Nested parameters in VB.Net and SQL Server

0

Greetings to all, I am making an application in VB.NET and SQL Server. I have a stored procedure that retrieves all the columns of a table, passing as a parameter the password, the detail is that I need to save the recovered data to send it as a parameter to another stored procedure.

Some idea you can give me, I would appreciate it a lot.

It's the code part to log in.

Public Function validaUsuario(ByVal dts As vusuario) As Boolean
        Try
            conectar()
            cmd = New SqlCommand("pro_recupera_usuario")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = con

            cmd.Parameters.AddWithValue("@p1", dts.gpassword)

            Dim dr As SqlDataReader
            dr = cmd.ExecuteReader

            If dr.HasRows = True Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectar()
        End Try
    End Function

Code that I use from the form

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click

        Try
            Dim dts As New vusuario
            Dim func As New fusuario

            dts.gpassword = Trim(txtPassword.Text)
            If func.validaUsuario(dts) = True Then
                MsgBox("Existe usuario")
            Else
                MsgBox("No existe usuario")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

For now, it only gives me the message "There is a user".

but there I need to make a comparison of the recovered data to know which form to show later since I have 3 types of forms: A (admin), B (leaders) and C (users)

Finally, this is the query where I occupy the recovered data:

Public Function mostrar() As DataTable
        Try
            conectar()
            cmd = New SqlCommand("pro_compras_ConsultaxVendedor")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = con
            cmd.Parameters.AddWithValue("@id_vendedor", 8)

            If cmd.ExecuteNonQuery Then
                Dim dt As New DataTable
                Dim da As New SqlDataAdapter(cmd)
                da.Fill(dt)
                Return dt
            Else
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectar()
        End Try
    End Function

In the place of number 8 in this row:

cmd.Parameters.AddWithValue("@id_vendedor", 8)

would pass the value of the user that the password belongs to.

The stored procedure is as follows:

create procedure pro_recupera_usuario
  @p1 integer(8) 
 as
  select PK_id_usuario, nombre_usuario, sucursal_usuario, estatus_usuario
   from tblUsuario
   where password= @p1;

I hope to understand and hopefully you can help me. THANK YOU

    
asked by Silvestre Silva 02.01.2018 в 23:01
source

0 answers