Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/09/2012, 16:55
solosoy
 
Fecha de Ingreso: julio-2012
Mensajes: 9
Antigüedad: 11 años, 10 meses
Puntos: 0
Pregunta busqueda con filtro de milllones de datos

Buenas tardes tengo un problema; tengo millones de datos como 2 millones q seguiran aunmentando, lo que quiero es que cuando haga una busqueda filtrando dos a tres campos no se cuelgue; se colgaba pq yo llamaba la base de datos asi:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim seleccion As String = "SELECT * FROM base"

da = New SqlDataAdapter(seleccion, conexion)
dt = New DataTable
da.Fill(dt)

' enlazar el DataTable al BindingSource
BindingSource1.DataSource = dt

End Sub

Private Sub Aplicar_Filtro()

' filtrar por el campo Producto
'''''''''''''''''''''''''''''''''''''''''''''''''' ''
Dim ret As Integer = Filtrar_DataGridView( _
"DESC_COMER", _
txtbuscar.Text.Trim, _
BindingSource1, _
dgvdiarios)

If ret = 0 Then
' si no hay registros cambiar el color del txtbox
txtbuscar.BackColor = Color.Red
Else
txtbuscar.BackColor = Color.White
End If
' visualizar la cantidad de registros
Me.Text = ret & " Registros encontrados"

End Sub
Function Filtrar_DataGridView( _
ByVal Columna As String, _
ByVal texto As String, _
ByVal BindingSource As BindingSource, _
ByVal DataGridView As DataGridView) As Integer

' verificar que el DataSource no esté vacio
If BindingSource1.DataSource Is Nothing Then
Return 0
End If

Try

BindingSource.Filter = "DESC_COMER like '" & txtbuscar.Text & "%' AND DESC_OTROS like '" & Txtreferencias.Text & "%'"
'BindingSource.Filter = "DESC_COMER like '" & txtbuscar.Text & "'%{0}%' AND DESC_OTROS like '" & Txtreferencias.Text & "%'AND DESC_FOPRE like '" & Txtotros.Text & "%'"


' enlzar el datagridview al BindingSource
DataGridView.DataSource = BindingSource.DataSource

' retornar la cantidad de registros encontrados
Return BindingSource.Count

' errores
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
End Try

Return 0

End Function

Private Sub btnexaminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexaminar.Click
'Aplicar_Filtro()
End Sub

Private Sub txtbuscar_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtbuscar.TextChanged
Aplicar_Filtro()
End Sub

Private Sub Txtreferencias_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtreferencias.TextChanged
Aplicar_Filtro()
End Sub

Private Sub Txtotros_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtotros.TextChanged
Aplicar_Filtro()
End Sub

con este ejemplo mostraba cuando eran 1000 datos sin problemas; pero ahora como son mas de dos milllones se me cuelga no quiero q muestre todos los milllones de datos en el datagridview sino los datos filtrados al hacer la busqueda; todo en visual.net 2005 y sql2000

Graxias de antemano.