Principales respuestas
dos datatable en un dataset

Pregunta
-
Private Function Obtener_Recibo() As RECIBO_PAGO_DS Using cnn As New SqlConnection(configuracion.ConnectionString) Using cmd As SqlCommand = cnn.CreateCommand() cmd.CommandText = "Select A.*,B.Cant,B.Descripcion,B.Cantidad, " & "(C.Nombre + ' ' + C.Inicial + ' ' + C.Apellido_1 + ' ' + C.Apellido_2) as Nombre_Estudiante, " & "(D.Nombre + ' ' + D.Apellido_1 + ' ' + D.Apellido_2) as Nombre_Empleado, " & "E.Nom_Ins,E.Nom_Rec,Finanzas " & "From Finanzas_Recibos_Tabla A " & "left join Finanzas_Recibos_Detalles_Tabla B on A.Num_Recibo=B.Num_Recibo " & "left join Adm_Estudiantes_Tabla C on A.Num_Estudiante = C.Num_Estudiante " & "left join Rec_Hum_Empleados_Tabla D on A.Num_Empleado=D.Numero_Empleado " & "left join Config_Encabezados_Reportes_Tabla E " & "where A.Num_Recibo =@Num_Recibo " cmd.Parameters.AddWithValue("@Num_Recibo", txtnumrecibo.Text) Dim DA As New SqlDataAdapter(cmd) Dim DS As New RECIBO_PAGO_DS DA.Fill(DS, "Finanzas_Recibos_Tabla") Return DS End Using End Using End Function Private Function Obtener_Recibo1() As RECIBO_PAGO_DS Using cnn As New SqlConnection(configuracion.ConnectionString) Using cmd As SqlCommand = cnn.CreateCommand() cmd.CommandText = "Select * " & "From Finanzas_Recibos_Pagos_Tabla " & "where Num_Recibo =@Num_Recibo " cmd.Parameters.AddWithValue("@Num_Recibo", txtnumrecibo.Text) Dim DA As New SqlDataAdapter(cmd) Dim DS As New RECIBO_PAGO_DS DA.Fill(DS, "Finanzas_Recibos_Pagos_Tabla") Return DS End Using End Using End Function
quiero en vez de tener dos funciones tener una sola osea dos command text dentro de una funcion utilizando el formato que uso para las funciones
Respuestas
-
Hola:
Prueba estoPrivate Function Obtener_Recibo() As RECIBO_PAGO_DS
Dim DS As New RECIBO_PAGO_DS
Try
Dim Consulta As String = String.Empty
Using cnn As New SqlConnection(configuracion.ConnectionString)
Consulta = "Select A.*,B.Cant,B.Descripcion,B.Cantidad, (C.Nombre + ' ' + C.Inicial + ' ' + C.Apellido_1 + ' ' + C.Apellido_2) as Nombre_Estudiante, (D.Nombre + ' ' + D.Apellido_1 + ' ' + D.Apellido_2) as Nombre_Empleado, E.Nom_Ins,E.Nom_Rec,Finanzas From Finanzas_Recibos_Tabla A left join Finanzas_Recibos_Detalles_Tabla B on A.Num_Recibo=B.Num_Recibo left join Adm_Estudiantes_Tabla C on A.Num_Estudiante = C.Num_Estudiante left join Rec_Hum_Empleados_Tabla D on A.Num_Empleado=D.Numero_Empleado left join Config_Encabezados_Reportes_Tabla E where A.Num_Recibo =@Num_Recibo"
Using cmd As New SqlCommand(Consulta, cnn)
cmd.Parameters.AddWithValue("@Num_Recibo", txtnumrecibo.Text)
Using DA As New SqlDataAdapter(cmd)
DA.Fill(DS, "Finanzas_Recibos_Tabla")
End Using
End Using
'
Consulta = "Select * From Finanzas_Recibos_Pagos_Tabla where Num_Recibo =@Num_Recibo"
Using cmd As New SqlCommand(Consulta, cnn)
cmd.Parameters.AddWithValue("@Num_Recibo", txtnumrecibo.Text)
Using DA As New SqlDataAdapter(cmd)
DA.Fill(DS, "Finanzas_Recibos_Pagos_Tabla")
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return DS
End FunctionUn saludo desde Bilbo
Carlos- Marcado como respuesta Efrain Diaz viernes, 17 de abril de 2020 9:50
Todas las respuestas
-
Hola:
Prueba estoPrivate Function Obtener_Recibo() As RECIBO_PAGO_DS
Dim DS As New RECIBO_PAGO_DS
Try
Dim Consulta As String = String.Empty
Using cnn As New SqlConnection(configuracion.ConnectionString)
Consulta = "Select A.*,B.Cant,B.Descripcion,B.Cantidad, (C.Nombre + ' ' + C.Inicial + ' ' + C.Apellido_1 + ' ' + C.Apellido_2) as Nombre_Estudiante, (D.Nombre + ' ' + D.Apellido_1 + ' ' + D.Apellido_2) as Nombre_Empleado, E.Nom_Ins,E.Nom_Rec,Finanzas From Finanzas_Recibos_Tabla A left join Finanzas_Recibos_Detalles_Tabla B on A.Num_Recibo=B.Num_Recibo left join Adm_Estudiantes_Tabla C on A.Num_Estudiante = C.Num_Estudiante left join Rec_Hum_Empleados_Tabla D on A.Num_Empleado=D.Numero_Empleado left join Config_Encabezados_Reportes_Tabla E where A.Num_Recibo =@Num_Recibo"
Using cmd As New SqlCommand(Consulta, cnn)
cmd.Parameters.AddWithValue("@Num_Recibo", txtnumrecibo.Text)
Using DA As New SqlDataAdapter(cmd)
DA.Fill(DS, "Finanzas_Recibos_Tabla")
End Using
End Using
'
Consulta = "Select * From Finanzas_Recibos_Pagos_Tabla where Num_Recibo =@Num_Recibo"
Using cmd As New SqlCommand(Consulta, cnn)
cmd.Parameters.AddWithValue("@Num_Recibo", txtnumrecibo.Text)
Using DA As New SqlDataAdapter(cmd)
DA.Fill(DS, "Finanzas_Recibos_Pagos_Tabla")
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return DS
End FunctionUn saludo desde Bilbo
Carlos- Marcado como respuesta Efrain Diaz viernes, 17 de abril de 2020 9:50
-