Hi Vasanth057,
Refer the below sample code.
You need to change the code as per your columnName and no of column to check in where condition.
C#
protected void Page_Load(object sender, EventArgs e)
{
int id = 1;
string name = "Maria";
string company = "Alfreds Futterkiste";
string city = "Boise";
string country = "Austria";
DataTable dt = GetDataTable();
var duplicate = from d in dt.AsEnumerable()
where d.Field<int>("Id") == id
&& d.Field<string>("Name") == name
&& d.Field<string>("Company") == company
&& d.Field<string>("City") == city
&& d.Field<string>("Country") == country
select d;
if (duplicate.Count() > 0)
{
Response.Write("Record already exist");
}
}
private DataTable GetDataTable()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] {
new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Company",typeof(string)) ,
new DataColumn("City",typeof(string)),
new DataColumn("Country",typeof(string))});
dt.Rows.Add(1, "Maria", "Alfreds Futterkiste", "Boise", "Austria");
dt.Rows.Add(2, "Mudassar Khan", "ASPSnippets", "Warszawa", "India");
dt.Rows.Add(3, "Ana Trujillo", "Ana Trujillo Emparedados y helados", "México D.F.", "France");
dt.Rows.Add(4, "Antonio Moreno", "Antonio Moreno Taquería", "Montréal", "Brazil");
return dt;
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim id As Integer = 1
Dim name As String = "Maria"
Dim company As String = "Alfreds Futterkiste"
Dim city As String = "Boise"
Dim country As String = "Austria"
Dim dt As DataTable = GetDataTable()
Dim duplicate = From d In dt.AsEnumerable() Where d.Field(Of Integer)("Id") = id AndAlso d.Field(Of String)("Name") = name AndAlso d.Field(Of String)("Company") = company AndAlso d.Field(Of String)("City") = city AndAlso d.Field(Of String)("Country") = country
If duplicate.Count() > 0 Then
Response.Write("Record already exist")
End If
End Sub
Private Function GetDataTable() As DataTable
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(4) {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Company", GetType(String)), New DataColumn("City", GetType(String)), New DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "Maria", "Alfreds Futterkiste", "Boise", "Austria")
dt.Rows.Add(2, "Mudassar Khan", "ASPSnippets", "Warszawa", "India")
dt.Rows.Add(3, "Ana Trujillo", "Ana Trujillo Emparedados y helados", "México D.F.", "France")
dt.Rows.Add(4, "Antonio Moreno", "Antonio Moreno Taquería", "Montréal", "Brazil")
Return dt
End Function