将与t-sql关系的多个表读入DataSet [英] Read multiple tables with relations with t-sql into DataSet
本文介绍了将与t-sql关系的多个表读入DataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以从多个表( t-sql
语句选择数据
> join )转换为字符串表示形式,并直接将此文本插入到数据集中(
DataSet.ReadXml(...) )
Is it possible to select data
with one t-sql
statement from multiple tables (join
) into a string representation and directly insert
this text into a data set (DataSet.ReadXml(...)
).
当然,我需要保持关系。
I need to preserve the relations, of course.
我已经看到一些使用 FOR XML
的复杂示例,但是有一个简单的方法?
I have seen some complex examples using FOR XML
, but is there a simple way?
推荐答案
好,我自己做了:
SQL = "SELECT table1.x, table2.z FROM table1
INNER JOIN table2 ON table1.ID = table2.SubID
FOR XML AUTO, XMLDATA";
和
DataSet data = new DataSet();
DbCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
data.ReadXml(((System.Data.SqlClient.SqlCommand)cmd).ExecuteXmlReader(),
xmlReadMode.Fragment);
这是它
这篇关于将与t-sql关系的多个表读入DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文