Click here to Skip to main content
15,887,391 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am try to index searcher in wpf application using lucene.net but into data bind the data did not comes in data grid and cuases an error .
VB
Private Sub Btn_Show_Click(sender As Object, e As RoutedEventArgs)
    'Try
    ' Results are collected as a List
    Dim Searchresults As New List(Of SearchResults)()
    Dim dt_Result As New DataTable
    Dim searchString As String = txtSearch.Text
    Dim query1 As String = "SELECT RecID, Tag, SbFldSrNo, SbFld, FValue, FValue_TBIL FROM biblidetails"
    conn.Open()
    adap.SelectCommand = New SqlCommand(query1, conn)
    adap.Fill(dt_Result)
    'End If
    Dim Field0, Field1, Field2, Field3, Field4, Field5 As String

    Field0 = dt_Result.Columns(0).Caption
    Field1 = dt_Result.Columns(1).Caption
    Field2 = dt_Result.Columns(2).Caption
    Field3 = dt_Result.Columns(3).Caption
    Field4 = dt_Result.Columns(4).Caption
    Field5 = dt_Result.Columns(5).Caption

    conn.Close()

    ' Specify the location where the index files are stored
    Dim indexFileLocation As String = "C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder"
    Dim dir As Lucene.Net.Store.Directory = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation)

    ' specify the search fields, lucene search in multiple fields
    Dim searchfields As String() = New String() {Field0, Field1, Field2, Field3, Field4, Field5}
    Dim indexSearcher As New IndexSearcher(dir)

    ' Making a boolean query for searching and get the searched hits
    Dim hits = indexSearcher.Search(QueryMaker(searchString, searchfields))

    For i As Integer = 0 To hits.Length() - 1

        Dim result As New SearchResults()

        result.RecID = hits.Doc(i).GetField(Field0).StringValue()
        result.Tag = hits.Doc(i).GetField(Field1).StringValue()
        result.SbFldSrNo = hits.Doc(i).GetField(Field2).StringValue()
        result.SbFld = hits.Doc(i).GetField(Field3).StringValue()
        result.FValue = hits.Doc(i).GetField(Field4).StringValue()
        result.FValue_TBIL = hits.Doc(i).GetField(Field5).StringValue()

        SearchResults.Add(result)

    Next

    indexSearcher.Close()

    dGridResults.ItemsSource = Searchresults
    dGridResults.DataBind() here comes an error
    'Catch ex As Exception
    'MsgBox(ex.Message)
    'End Try
End Sub
Posted

1 solution

In WPF you don't have a DataBind method for the DataGrid. When you set the ItemsSource, the data is automatically bound to the grid.

So just remove/comment out the line
VB
dGridResults.DataBind()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900