Refer the below sample code and implement it in your code as per your code logic.
C#
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", typeof(string)));
dt.Rows.Add("test1@test.com,test2@test.com,test3@test.com");
dt.Rows.Add("test4@test.com,test5@test.com,test6@test.com");
dt.Rows.Add("test7@test.com,test8@test.com,test9@test.com");
DataTable dtusercheck = dt;
DataTable dt2 = new DataTable();
dt2.Columns.Add(new DataColumn("Id", typeof(string)));
dt2.Rows.Add("test3@test.com");
DataTable dtuserinprojectornot = dt2;
DataTable dt3 = dtuserinprojectornot.Clone();
foreach (DataRow row1 in dtusercheck.Rows)
{
foreach (DataRow row2 in dtuserinprojectornot.Rows)
{
foreach (string emailId in row1["id"].ToString().Split(','))
{
if (emailId == row2["id"].ToString())
{
dt3.ImportRow(row2);
}
}
}
}
if (dt3.Rows.Count > 0)
{
lblErrMsg.Visible = true;
}
else
{
lblErrMsg.Visible = true;
}
VB.Net
Dim dt As DataTable = New DataTable()
dt.Columns.Add(New DataColumn("Id", GetType(String)))
dt.Rows.Add("test1@test.com,test2@test.com,test3@test.com")
dt.Rows.Add("test4@test.com,test5@test.com,test6@test.com")
dt.Rows.Add("test7@test.com,test8@test.com,test9@test.com")
Dim dtusercheck As DataTable = dt
Dim dt2 As DataTable = New DataTable()
dt2.Columns.Add(New DataColumn("Id", GetType(String)))
dt2.Rows.Add("test3@test.com")
Dim dtuserinprojectornot As DataTable = dt2
Dim dt3 As DataTable = dtuserinprojectornot.Clone()
For Each row1 As DataRow In dtusercheck.Rows
For Each row2 As DataRow In dtuserinprojectornot.Rows
For Each emailId As String In row1("id").ToString().Split(","c)
If emailId = row2("id").ToString() Then
dt3.ImportRow(row2)
End If
Next
Next
Next
If dt3.Rows.Count > 0 Then
lblErrMsg.Visible = True
Else
lblErrMsg.Visible = True
End If