如何使用多个表适配器查询中的行正确填充 DataGridView?
我正在执行一个临时查询来获取一组 ID,每个 ID 都进入表适配器的查询,填充行。
但是,除了使用表适配器上的 ClearBeforeFill 属性之外,我想不出任何其他方法来清除。
所有这些都相当于代码可以工作,但我觉得有点像黑客。
有谁知道正确/更好的方法来做到这一点? (注意:我知道内联 SQL 并不理想)
var db = new Data.PRDataDataContext();
verifiedLineItemsTableAdapter.ClearBeforeFill = true;
bool flag = true;
foreach (var affid in db.ExecuteQuery<int>(
@"
SELECT Item.affid
FROM dbo.Item INNER JOIN
dbo.Affiliate ON dbo.Item.affid = dbo.Affiliate.affid
WHERE Affiliate.name={0}
UNION
SELECT affid
FROM dbo.Publisher
WHERE name={0}"
, name))
{
Console.WriteLine("got " + affid);
verifiedLineItemsTableAdapter.FillByAffId(
publisherReportDataSet1.VerifiedLineItems, affid);
if (flag)
{
verifiedLineItemsTableAdapter.ClearBeforeFill = false;
flag = false;
}
}
I'm doin an ad-hoc query to get a set of ID's, each of which goes to a table adapter's query, populating rows.
However, I can't figure out any other way to clear other than using the ClearBeforeFill property on the table adapter.
All of this amounts to code that works but I feel is kind of a hack.
Does anyone know the right/better way to do this? (note: i'm aware inline SQL isn't ideal)
var db = new Data.PRDataDataContext();
verifiedLineItemsTableAdapter.ClearBeforeFill = true;
bool flag = true;
foreach (var affid in db.ExecuteQuery<int>(
@"
SELECT Item.affid
FROM dbo.Item INNER JOIN
dbo.Affiliate ON dbo.Item.affid = dbo.Affiliate.affid
WHERE Affiliate.name={0}
UNION
SELECT affid
FROM dbo.Publisher
WHERE name={0}"
, name))
{
Console.WriteLine("got " + affid);
verifiedLineItemsTableAdapter.FillByAffId(
publisherReportDataSet1.VerifiedLineItems, affid);
if (flag)
{
verifiedLineItemsTableAdapter.ClearBeforeFill = false;
flag = false;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将其分为 2 个独立的函数,然后将其连接起来
与此类似
,然后将它们连接起来
编辑: 然后您可以将其绑定到网格
I would divide it into 2 separate functions and join the up afterward
Similar to this
and then join them up
EDIT : you can then bind it to a grid