Refer below Sample code for your reference and implement in your code as per your code logic.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Employee");
dt.Columns.Add(new DataColumn("Id", typeof(string)));
dt.Columns.Add(new DataColumn("Empname", typeof(string)));
dt.Columns.Add(new DataColumn("Des", typeof(string)));
dt.Rows.Add(1, "sk", "eng");
dt.Rows.Add(2, "rm", "eng");
dt.Rows.Add(3, "sk", "dt");
ds.Tables.Add(dt);
Array distinctName;
for (int i = 0; i < ds.Tables.Count; i++)
{
distinctName = ds.Tables[i].AsEnumerable()
.GroupBy(x => x.Field<string>("Empname"))
.Select(g => new
{
Name = g.Key,
Count = g.Select(x => x.Field<string>("Empname")).Count()
}).ToArray();
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable("Employee")
dt.Columns.Add(New DataColumn("Id", GetType(String)))
dt.Columns.Add(New DataColumn("Empname", GetType(String)))
dt.Columns.Add(New DataColumn("Des", GetType(String)))
dt.Rows.Add(1, "sk", "eng")
dt.Rows.Add(2, "rm", "eng")
dt.Rows.Add(3, "sk", "dt")
ds.Tables.Add(dt)
Dim distinctName As Array
For i As Integer = 0 To ds.Tables.Count - 1
distinctName = ds.Tables(i).AsEnumerable().GroupBy(Function(x) x.Field(Of String)("Empname")).[Select](Function(g) New With {Key .Name = g.Key, Key .Count = g.[Select](Function(x) x.Field(Of String)("Empname")).Count()}).ToArray()
Next
End If
End Sub
Screenshot