You aren't consistent in the UPPER/lower case of the strings you use to index into dtrow and they don't always match the column names you specified above.
Private Sub Btn_Show_Click(sender As Object, e As RoutedEventArgs)
Dim dt As New DataTable()
Dim SearchCriteria = cmbSearch.Text
dt.Columns.Add("Title", GetType(String))
dt.Columns.Add("Author", GetType(String))
dt.Columns.Add("AccessionNo", GetType(String))
dt.Columns.Add("Location", GetType(String))
dt.Columns.Add("Status", GetType(String))
Dim xmldoc As New XmlDocument()
xmldoc.Load("C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder\Data.xml")
Dim nodeList As XmlNodeList = xmldoc.SelectNodes("/NewDataSet/Table")
If SearchCriteria = "Title" Then
For Each node As XmlNode In nodeList
Dim dtrow As DataRow = dt.NewRow()
If (LCase(node("title").InnerText).Contains(LCase(txtSearch.Text()))) Then
dtrow("Title") = node("title").InnerText
dtrow("Author") = node("Author").InnerText
dtrow("AccessionNo") = node("AccessionNo").InnerText
dtrow("Location") = node("location").InnerText
dtrow("Status") = node("status").InnerText
dt.Rows.Add(dtrow)
End If
Next
End If
If SearchCriteria = "Author" Then
For Each nodeAuthor As XmlNode In nodeList
Dim dtrow As DataRow = dt.NewRow()
If (LCase(nodeAuthor("Author").InnerText).Contains(LCase(txtSearch.Text()))) Then
dtrow("Title") = nodeAuthor("title").InnerText
dtrow("Author") = nodeAuthor("Author").InnerText
dtrow("AccessionNo") = nodeAuthor("AccessionNo").InnerText
dtrow("Location") = nodeAuthor("location").InnerText
dtrow("Status") = nodeAuthor("status").InnerText
dt.Rows.Add(dtrow)
End If
Next
End If
dGridResults.ItemsSource = dt.DefaultView
End Sub
You should use named constants instead of in-line strings to avoid this. The constants define the string value and the compiler will enforce your using the correct casing/spelling of the names.