Hi Waghmare,
For reading Excel i have used ClosedXML Library. Refer below link for details.
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox runat="server" ID="txtSearchTerm" />
<asp:Button Text="Search" runat="server" OnClick="Search" /><br />
<asp:Label ID="lblText" runat="server" />
Namespaces
C#
using ClosedXML.Excel;
VB.Net
Imports ClosedXML.Excel
Code
C#
protected void Search(object sender, EventArgs e)
{
string filePath = Server.MapPath("~/Files/Excel.xlsx");
using (XLWorkbook workBook = new XLWorkbook(filePath))
{
// Read the first Sheet from Excel file.
IXLWorksheet workSheet = workBook.Worksheet(1);
// Loop through the Worksheet rows.
foreach (IXLRow row in workSheet.Rows())
{
// Loop through the cells of each row.
foreach (IXLCell cell in row.Cells())
{
if (cell.Value.ToString().ToLower().Contains(txtSearchTerm.Text.ToLower().Trim()))
{
lblText.Text = "Text Found";
return;
}
}
}
}
}
VB.Net
Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs)
Dim filePath As String = Server.MapPath("~/Files/Excel.xlsx")
' Read the first Sheet from Excel file.
Using workBook As XLWorkbook = New XLWorkbook(filePath)
Dim workSheet As IXLWorksheet = workBook.Worksheet(1)
' Loop through the Worksheet rows.
For Each row As IXLRow In workSheet.Rows()
' Loop through the cells of each row.
For Each cell As IXLCell In row.Cells()
If cell.Value.ToString().ToLower().Contains(txtSearchTerm.Text.ToLower().Trim()) Then
lblText.Text = "Text Found"
Return
End If
Next
Next
End Using
End Sub
Screenshot