El Guru Programador
Usuario DESCONOCIDO | Registrate Gratis | Usuarios Registrados
Foro de Visual Basic/VB.NET
Foros del Guru > Visual Basic/VB.NET
Usuario consulta a datos con varios parame...
Desconocido
Enviado - 30/8/2004
 
Estoy intentando hacer una consulta con cuatro parametros de busqueda y siempre me da como resultado la base de datos completa.
Adjunto el código, a ver si alguien me puede echar una mano por favor.

Private Sub btnDEFiltrado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDEFiltrado.Click
'Declaramos la variable que contendrá la sentencia SQL
'que ejecutaremos para rellenar el DataGrid
Dim strSQLCTaskForce As String = ""
Dim strSQLCFecha As String = ""
Dim strSQLCComercial As String = ""
Dim strSQLCEstado As String = ""
Dim EF As String = "Introduzca un parámetro para el Filtrado"
'Selección de Nombre de Producto
'Establecemos su sentencia SQL correspondiente
strSQLCTaskForce = "Select * From DE Where Task_Force like '%" & cbxTaskForce.Text & "%'"
strSQLCFecha = "Select * From DE Where MES like '%" & cbxDEFecha.Text & "%'"
strSQLCComercial = "Select * From DE Where Nombre_comercial like '%" & cbxDEComercial.Text & "%'"
strSQLCEstado = "Select * From DE Where Estado like '%" & cbxDEEstado.Text & "%'"
'Declaramos el DataSet dónde volcaremos
'los datos seleccionados para luego
'trabajar con ellos desconectándonos
'de la fuente de datos directa
Dim DsDE1 As New DataSet
'Ejecutamos la sentencia SQL con captura de errores
Try
'Establecemos las propiedades de conexión del adaptador
'Por un lado la conexión
'Por otro lado la sentencia SQL correspondiente
With OleDbDataAdapter6.SelectCommand
.Connection = OleDbConnection1
If cbxTaskForce.Text = "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCTaskForce
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text = "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCFecha
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text = "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCComercial
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text = "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCFecha
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text = "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCComercial
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text = "" And cbxDEComercial.Text = "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCFecha
.CommandText = strSQLCComercial
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text = "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCFecha
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text = "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCComercial
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text = "" And cbxDEFecha.Text = "" And cbxDEComercial.Text = "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCTaskForce
.CommandText = strSQLCFecha
.CommandText = strSQLCComercial
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text = "" And cbxDEComercial.Text = "" And cbxDEEstado.Text <> "" Then
.CommandText = strSQLCFecha
.CommandText = strSQLCComercial
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text = "" And cbxDEComercial.Text <> "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCFecha
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text = "" And cbxDEComercial.Text = "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCFecha
.CommandText = strSQLCComercial
.CommandText = strSQLCEstado
ElseIf cbxTaskForce.Text <> "" And cbxDEFecha.Text <> "" And cbxDEComercial.Text = "" And cbxDEEstado.Text = "" Then
.CommandText = strSQLCComercial
.CommandText = strSQLCEstado
Else
MsgBox(EF)

End If

End With
'Ejecutamos el adaptador y rellenamos el DataSet con los datos
OleDbDataAdapter6.Fill(DsDE1, "DE")
'Miramos si hay datos en el DataSet
If DsDE1.Tables(0).Rows.Count > 0 Then
'Si hay datos, mostramos los datos y mostramos el DataGrid
DataGrid1.DataSource = DsDE1.Tables(0)
Label2.Text = DsDE1.Tables(0).Rows.Count & " registro(s)"
DataGrid1.Visible = True
Else
'Sino hay datos, no mostramos el DataGrid
DataGrid1.Visible = False
Label2.Text = "0 registro(s)"
End If
Catch ex As Exception
'Si ocurre una excepción, mostramos un mensaje
'en pantalla indicando el error ocurrido
MessageBox.Show(ex.Message)
End Try
End Sub

muchas gracias
 
 

 

Contactos myStudio Network