如何使用数据视图检查相同的值

How to use dataview to check same Value

DataTable dt = new DataTable();
res.Fill(dt);

获取sql数据码

DataRow dr = dt.NewRow();
dr[0] = tt_id;
dr[1] = fault_desc;
dr[2] = tt_time;

dt.Rows.Add(dr);

DataView dv = new DataView(dt);

Response.Write(dv);

if (dv.Count != dv.ToTable(true, "tt_id").Rows.Count) {
  // string sqlstr = string.Format("insert 
}

我想用dataview查看之前sql中已经存在的新数据 如果存在取消插入。 问题是回应说我有同样的价值 但我检查了它在 dv 中没有任何相同值的地方。 这里有什么问题?

var duplicateValues = (from row in dt.AsEnumerable()
                   orderby row.Field<string>("Id")
                   select new DuplicateObject
                   {
                       Id = row.Field<string>("Id"),
                       Name = row.Field<string>("Name"),
                       Skill = row.Field<string>("Skill")
                   }).Distinct(new DuplicateObjectComparer()).ToList();

string dupValue = string.Empty;

foreach (var dup in duplicateValues)
{
dupValue = dup.Id + " - " + dup.Name + " - " + dup.Skill;
Console.WriteLine("Duplicate entry:" + dupValue);
}

if (duplicateValues.Count == 0)
Console.WriteLine("No duplicate entry");
// Supporting classes
// Gives a strongly type class from the Linq query    
public class DuplicateObject
{
  public string Id { get; set; }
  public string Name { get; set; }
  public string Skill { get; set; }
}