Hi Vidhya,
Please refer below Sample.
HTML
<asp:TextBox runat="server" ID="txtQuarter"></asp:TextBox>
<asp:Button Text="Submit" runat="server" ID="btnSubmit" OnClick="Submit" />
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Submit(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[6] { new DataColumn("ID", typeof(int)),
new DataColumn("Acount", typeof(string)),
new DataColumn("Name", typeof(string)),
new DataColumn("Quarter", typeof(string)),
new DataColumn("FY", typeof(int)),
new DataColumn("Income_percent", typeof(int))});
dt.Rows.Add(1, "ABC", "Ram", "Q1", 2011, 50);
dt.Rows.Add(2, "XYZ", "Hari", "Q4", 2011, 35);
dt.Rows.Add(3, "ABC", "Rohit", "Q3", 2011, 40);
dt.Rows.Add(4, "ABC", "Ram", "Q2", 2011, 25);
dt.Rows.Add(5, "XYZ", "Hari", "Q3", 2011, 60);
bool exists = dt.Select().ToList().Exists(row => row["Quarter"].ToString().ToUpper() == txtQuarter.Text);
if (exists)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Record Exists.');", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Record Not Exists.');", true);
}
}
VB.Net
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(5) {New DataColumn("ID", GetType(Integer)), New DataColumn("Acount", GetType(String)), New DataColumn("Name", GetType(String)), New DataColumn("Quarter", GetType(String)), New DataColumn("FY", GetType(Integer)), New DataColumn("Income_percent", GetType(Integer))})
dt.Rows.Add(1, "ABC", "Ram", "Q1", 2011, 50)
dt.Rows.Add(2, "XYZ", "Hari", "Q4", 2011, 35)
dt.Rows.Add(3, "ABC", "Rohit", "Q3", 2011, 40)
dt.Rows.Add(4, "ABC", "Ram", "Q2", 2011, 25)
dt.Rows.Add(5, "XYZ", "Hari", "Q3", 2011, 60)
Dim exists As Boolean = dt.[Select]().ToList().Exists(Function(row) row("Quarter").ToString().ToUpper() = txtQuarter.Text)
If exists Then
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Record Exists.');", True)
Else
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Record Not Exists.');", True)
End If
End Sub
Screenshot