是否可以通过数据集中的相关数据表对数据表中的数据进行排序?
我已经使用 ORM 这么久了,我似乎已经忘记了 dotnet 中的大部分基本数据处理技能:(
是否可以做这样的事情?
DataSet ds = new DataSet();
var compiledConnection = new SqlConnection(cDbConnectionString);
SqlDataAdapter daChart = new SqlDataAdapter("select * from Chart", compiledConnection);
daChart.Fill(ds, "chart");
if (ds.Tables["chart"].Rows.Count > 0)
{
var sourceConnection = new SqlConnection(sourceDbConnectionString);
SqlDataAdapter daSource = new SqlDataAdapter("select * from source", sourceConnection);
daSource.Fill(ds, "source");
DataRelation chart_source = new DataRelation("dr", ds.Tables["chart"].Columns["intItemId"],
ds.Tables["source"].Columns["intRowId"], false);
ds.Relations.Add(chart_source);
}
然后使用表“图表”中的一列进行排序表“源”中的数据跨数据关系?
(在有人问之前,这两个表位于不同站点上的 SqlServer 的单独实例中,因此将数据作为一个表拉取并不是一项简单的任务。因此这种方法)
干杯, 马特
I've been using ORM's for so long, I appear to have forgotten most of my basic data handling skills in dotnet :(
Is it possibly to do something like this?
DataSet ds = new DataSet();
var compiledConnection = new SqlConnection(cDbConnectionString);
SqlDataAdapter daChart = new SqlDataAdapter("select * from Chart", compiledConnection);
daChart.Fill(ds, "chart");
if (ds.Tables["chart"].Rows.Count > 0)
{
var sourceConnection = new SqlConnection(sourceDbConnectionString);
SqlDataAdapter daSource = new SqlDataAdapter("select * from source", sourceConnection);
daSource.Fill(ds, "source");
DataRelation chart_source = new DataRelation("dr", ds.Tables["chart"].Columns["intItemId"],
ds.Tables["source"].Columns["intRowId"], false);
ds.Relations.Add(chart_source);
}
And then use one of the columns in the table "chart" to order the data in the table "source" across the datarelation?
(Before anyone asks, these two tables are in separare instances of SqlServer on separate sites, so just pulling the data as one table is not a straightforward task. Hence this approach)
Cheers,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是创建了一个外键的等价物。您似乎想要相当于 INNER JOIN 的东西。
除了创建关系之外,还需要将一个的所有列添加到另一个中,循环填充行和 GetParentRows。 MS 有一些很好的起点代码:
http://support.microsoft.com/kb/326080
编辑。您还可以通过创建链接服务器并使用 4 个部分名称 [服务器].[数据库].[所有者].[表] 来创建 SQL 版本
That just creates the equivalent of a foreign key. You seem to want the equivalent of an INNER JOIN.
In addition to creating the relationship, it requires adding all the columns of one to the other, loops to fill in the rows and GetParentRows. MS has some good starting point code:
http://support.microsoft.com/kb/326080
EDIT. You could also do a SQL version, by creating a linked server and using 4 part names [server].[database].[owner].[table]
感谢您的建议,但我发现您可以使用 LINQ 更轻松地做到这一点:
Thanks for the suggestion, but I discovered you can do it with LINQ rather more easily: