locked
Filtering and searching a dataview RRS feed

  • Question

  • User1256512446 posted

    Hi all:

    I have a dataview where I ca filter and search

    Filtering rows shows only the records that match a condition highlighting all

    Searching rows shows all the records highlighting only those tha match the condition

    The condition is

    camp1<>'ejemplo1' or campo2='ejemplo2'

    I use rowfilter, but it retuurns only those records that match the condition. It is not search, only filter

    How to do the search?

    TIA

    Sunday, August 9, 2015 11:20 AM

Answers

  • User281315223 posted

    Generally, filtering is going to completely limit the returning results by only displaying those that meet all of your credentials (i.e. camp <> 'ejemplo1' OR campo2='ejemplo2') where as a search would likely be more like a WHERE clause in SQL syntax and might be done after any filters have been applied. You might think of a filter as a logical AND (as it requires all conditions be met) where as a search might be an OR.

    Do you have any code related to this as it might make it a bit easier to get an idea of what is going on?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 9, 2015 11:37 AM
  • User-219423983 posted

    Hi volar5,

    I think there may be a mistake you could take a look. If I’m wrong, please ignore what I said.

    The function rellenar_ficheros_privado set a DataView to Session(“ficherosprivado”), the function rellenar_ficheros_publico set the result to Session(“ficherospublico”). But in your top snippet,  you just use string “ficherosprivado” to check the session whether is null or not. Here, I guess you want to check the two different sessions. So you should make a change by adding new string equals “ficherospublico” to check session(“ficherospublico”).

    Besides, the two functions are just setting the whole datatable to the session and then get the session to a new dataview for searching and filtering. It couldn’t achieve your initial needs. About “what to put when not blnfiltrar?”,  I think the searching and filtering have the same result, they all just get the Data that meets certain conditions. So I think, here you don’t need to use the judgment.

    https://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    I hope it’s useful to you.

    Best Regards,

    Weibo Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 10, 2015 6:57 AM

All replies

  • User281315223 posted

    Generally, filtering is going to completely limit the returning results by only displaying those that meet all of your credentials (i.e. camp <> 'ejemplo1' OR campo2='ejemplo2') where as a search would likely be more like a WHERE clause in SQL syntax and might be done after any filters have been applied. You might think of a filter as a logical AND (as it requires all conditions be met) where as a search might be an OR.

    Do you have any code related to this as it might make it a bit easier to get an idea of what is going on?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 9, 2015 11:37 AM
  • User1256512446 posted

    Hi:

    It is

                        If strtabla = "ficherosprivado" Then
                            If Session(strtabla) Is Nothing Then rellenar_ficheros_privado()
                        Else
                            If Session(strtabla) Is Nothing Then rellenar_ficheros_publico()
                        End If
                        dv = Session(strtabla)
                        If blnfiltrar Then
                            dv.RowFilter = strcondicion
                            s.Caption = dv.Count
                        Else
                            'dv.RowFilter = strcondicion
                            s.Caption = dv.Count
                        End If
    
        Sub rellenar_ficheros_privado(Optional orden As String = "concepto", Optional direccion As String = "asc")
            Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString)
            Dim sqlc As New SqlCommand("seleccionar_datos_obras", cnconexion)
            Dim strcarpeta As String, intobra As Integer = Request.QueryString("obra"), strfichero As String, dt As New DataTable, dr As DataRow, fi As FileInfo
            Dim strfoundfile As String, dectamano As Decimal, strtamano As String, sqlr As SqlDataReader, blnimprimir As Boolean = Request.QueryString("imprimir") IsNot Nothing
            Dim dv As DataView
            sqlc.CommandType = CommandType.StoredProcedure
            sqlc.Parameters.AddWithValue("@obra", intobra)
            sqlc.Parameters.Add("@fichero", SqlDbType.NVarChar, 25)
            strcarpeta = Choose(intobra, "Anuncios", "Aplicaciones", "Articulos", "Canciones", "Cuadros", "Cuentos", "Cursos", "Diapositivas", "Documentales", "Estudios", "Eventos", "Fotos", "Negocios", "Novelas", "Peliculas", "Poemas")
            dt.Columns.Add("id0", System.Type.GetType("System.Int16"))
            dt.Columns.Add("concepto", System.Type.GetType("System.String"))
            dt.Columns.Add("fichero", System.Type.GetType("System.String"))
            dt.Columns.Add("tamano", System.Type.GetType("System.String"))
            For Each strfoundfile In My.Computer.FileSystem.GetFiles(Server.MapPath("../" & strcarpeta & " privado/"), Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.*")
                strtamano = " kb."
                fi = New FileInfo(strfoundfile)
                If (File.GetAttributes(fi.FullName) And FileAttributes.Hidden) <> FileAttributes.Hidden Then
                    strfichero = fi.Name
                    sqlc.Parameters("@fichero").Value = strfichero
                    cnconexion.Open()
                    sqlr = sqlc.ExecuteReader
                    sqlr.Read()
                    dr = dt.NewRow()
                    If sqlr.HasRows Then
                        dr("id0") = sqlr("id0")
                        dr("concepto") = sqlr("concepto")
                        dr("fichero") = fi.Name
                        dectamano = fi.Length / 1024
                        If dectamano >= 1000 Then
                            dectamano /= 1000
                            strtamano = " mb."
                        End If
                        dr("tamano") = Format(dectamano, "n2") & strtamano
                    Else
                        dr("concepto") = "--"
                        dr("fichero") = "Sobra " & fi.Name
                        dr("id0") = 0
                        dectamano = fi.Length / 1024
                        If dectamano >= 1000 Then
                            dectamano /= 1000
                            strtamano = " mb."
                        End If
                        dr("tamano") = Format(dectamano, "n2") & strtamano
                    End If
                    dt.Rows.Add(dr)
                    sqlr.Close()
                    cnconexion.Close()
                End If
            Next
            sqlc.Parameters.Clear()
            sqlc.Parameters.AddWithValue("@obra", intobra)
            sqlc.Parameters.AddWithValue("@verficheros", True)
            cnconexion.Open()
            sqlr = sqlc.ExecuteReader
            Do While sqlr.Read
                fi = Nothing
                strfichero = Trim(sqlr("fichero"))
                If strfichero <> "" Then
                    fi = New FileInfo(Server.MapPath("../" & strcarpeta & " privado/") & strfichero)
                    If Not fi.Exists Then
                        dr = dt.NewRow()
                        dr("id0") = sqlr("id0")
                        dr("concepto") = sqlr("concepto")
                        dr("fichero") = "Falta " & strfichero
                        dr("tamano") = "0 kb."
                        dt.Rows.Add(dr)
                    End If
                End If
            Loop
            sqlr.Close()
            cnconexion.Close()
            dv = New DataView(dt)
            dv.Sort = orden & " " & direccion
            gvficherosprivado.DataSource = dv
            Session("ficherosprivado") = dv
            If Not blnimprimir Then gvficherosprivado.PageSize = registrospagina()
            gvficherosprivado.DataBind()
        End Sub
    
        Sub rellenar_ficheros_publico(Optional orden As String = "concepto", Optional direccion As String = "asc")
            Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString)
            Dim sqlc As New SqlCommand("seleccionar_desglose_obras", cnconexion)
            Dim strcarpeta As String, intobra As Integer = Request.QueryString("obra"), strfichero As String, dt As New DataTable, dr As DataRow, fi As FileInfo
            Dim strfoundfile As String, dectamano As Decimal, strtamano As String, sqlr As SqlDataReader, blnimprimir As Boolean = Request.QueryString("imprimir") IsNot Nothing
            Dim dv As DataView
            sqlc.CommandType = CommandType.StoredProcedure
            sqlc.Parameters.AddWithValue("@obra", intobra)
            sqlc.Parameters.Add("@fichero", SqlDbType.NVarChar, 25)
            strcarpeta = Choose(intobra, "Anuncios", "Aplicaciones", "Articulos", "Canciones", "Cuadros", "Cuentos", "Cursos", "Diapositivas", "Documentales", "Estudios", "Eventos", "Fotos", "Negocios", "Novelas", "Peliculas", "Poemas")
            dt.Columns.Add("id0", System.Type.GetType("System.Int16"))
            dt.Columns.Add("concepto", System.Type.GetType("System.String"))
            dt.Columns.Add("fichero", System.Type.GetType("System.String"))
            dt.Columns.Add("tamano", System.Type.GetType("System.String"))
            For Each strfoundfile In My.Computer.FileSystem.GetFiles(Server.MapPath("../" & strcarpeta & " publico/"), Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.*")
                fi = New FileInfo(strfoundfile)
                If (File.GetAttributes(fi.FullName) And FileAttributes.Hidden) <> FileAttributes.Hidden Then
                    strfichero = fi.Name
                    sqlc.Parameters("@fichero").Value = strfichero
                    cnconexion.Open()
                    sqlr = sqlc.ExecuteReader
                    sqlr.Read()
                    dr = dt.NewRow()
                    strtamano = " kb."
                    If sqlr.HasRows Then
                        dr("id0") = sqlr("id0")
                        dr("concepto") = sqlr("concepto")
                        dr("fichero") = fi.Name
                        dectamano = fi.Length / 1024
                        If dectamano >= 1000 Then
                            dectamano /= 1000
                            strtamano = " mb."
                        End If
                        dr("tamano") = Format(dectamano, "n2") & strtamano
                    Else
                        dr("id0") = 0
                        dr("concepto") = "--"
                        dr("fichero") = "Sobra " & fi.Name
                        dectamano = fi.Length / 1024
                        If dectamano >= 1000 Then
                            dectamano /= 1000
                            strtamano = " mb."
                        End If
                        dr("tamano") = Format(dectamano, "n2") & strtamano
                    End If
                    dt.Rows.Add(dr)
                    sqlr.Close()
                    cnconexion.Close()
                End If
            Next
            sqlc.Parameters.Clear()
            sqlc.Parameters.AddWithValue("@obra", intobra)
            sqlc.Parameters.AddWithValue("@verficheros", True)
            cnconexion.Open()
            sqlr = sqlc.ExecuteReader
            Do While sqlr.Read
                strfichero = Trim(sqlr("fichero"))
                If strfichero <> "" Then
                    fi = Nothing
                    fi = New FileInfo(Server.MapPath("../" & strcarpeta & " publico/") & strfichero)
                    If Not fi.Exists Then
                        dr = dt.NewRow()
                        dr("id0") = sqlr("id0")
                        dr("concepto") = sqlr("concepto")
                        dr("fichero") = "Falta " & strfichero
                        dr("tamano") = "0 kb."
                        dt.Rows.Add(dr)
                    End If
                End If
            Loop
            sqlr.Close()
            cnconexion.Close()
            dv = New DataView(dt)
            dv.Sort = orden & " " & direccion
            gvficherospublico.DataSource = dv
            Session("ficherospublico") = dv
            If Not blnimprimir Then gvficherospublico.PageSize = registrospagina()
            gvficherospublico.DataBind()
        End Sub
    

    strcondicion is the condition
    blnfiltrar is when filters, in other case it is a search

    what to put when not blnfiltrar?

    TIA

    Sunday, August 9, 2015 12:47 PM
  • User-219423983 posted

    Hi volar5,

    I think there may be a mistake you could take a look. If I’m wrong, please ignore what I said.

    The function rellenar_ficheros_privado set a DataView to Session(“ficherosprivado”), the function rellenar_ficheros_publico set the result to Session(“ficherospublico”). But in your top snippet,  you just use string “ficherosprivado” to check the session whether is null or not. Here, I guess you want to check the two different sessions. So you should make a change by adding new string equals “ficherospublico” to check session(“ficherospublico”).

    Besides, the two functions are just setting the whole datatable to the session and then get the session to a new dataview for searching and filtering. It couldn’t achieve your initial needs. About “what to put when not blnfiltrar?”,  I think the searching and filtering have the same result, they all just get the Data that meets certain conditions. So I think, here you don’t need to use the judgment.

    https://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    I hope it’s useful to you.

    Best Regards,

    Weibo Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 10, 2015 6:57 AM