User-271186128 posted
Hi aoshi_kh,
As for this issue, I suggest you could populate the result to a DataTable or DataSet by using the DataAdapter. Then you could using for loop to check the values. Like this:
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("StuId"), new DataColumn("StuName"), new DataColumn("Course") });
dt.Rows.Add(1001, "AAA", "English");
dt.Rows.Add(1002, "AAA", "Math");
dt.Rows.Add(1003, "CCC", "Math");
dt.Rows.Add(1004, "CCC", "English");
dt.Rows.Add(1005, "EEE", "English");
int count=0;
string name ="AAA";
for (int i = 0; i < dt.Rows.Count - 1; i++)
{
if ((dt.Rows[i]["StuName"].ToString().Equals(name)) || dt.Rows[i + 1]["StuName"].ToString().Equals(name))
{
count++;
break;
}
}
Response.Write(count.ToString());
As for populating a DataSet from a DataAdapter, please refer to this link:
https://msdn.microsoft.com/en-us/library/bh8kx08z(v=vs.110).aspx
Best Regards,
Dillion