我曾作过这个,想记录下来,不知道是不是很好的实现方式(本来想写最好的实现方式的,但想到这些绝对的词少用为妙);
这个包含是指两个ds的表只有一个,且他们的列都相同,都有一个唯一的列ID,但是它们的数据集不同,我想知道其中的一个ds的表的每个ID都在另一个ds表中出现了。
DataView dtv1 = ds1.Tables["table"].DefaultView;
DataView dtv2 = ds2.Tables["table"].DefaultView;
if (ds1.Tables["table"].Rows.Count > 0)
{
int i = 0;
for (; i < dtv2.Count; i++)
{
dtv1.RowFilter = dtv1.RowFilter == "" ? "ID =" + dtv2[i]["ID"] : dtv1.RowFilter + " or ID =" + dtv2[i]["ID"];
}
if (dtv1.Count != i)
{
MessageBox.Show("不包含!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
else
{
MessageBox.Show("包含!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return true;
}
}
DataView dtv2 = ds2.Tables["table"].DefaultView;
if (ds1.Tables["table"].Rows.Count > 0)
{
int i = 0;
for (; i < dtv2.Count; i++)
{
dtv1.RowFilter = dtv1.RowFilter == "" ? "ID =" + dtv2[i]["ID"] : dtv1.RowFilter + " or ID =" + dtv2[i]["ID"];
}
if (dtv1.Count != i)
{
MessageBox.Show("不包含!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
else
{
MessageBox.Show("包含!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return true;
}
}