问题
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.
I have seen some complex examples using FOR XML
, but is there a simple way?
回答1:
well, I did it myself:
SQL = "SELECT table1.x, table2.z FROM table1
INNER JOIN table2 ON table1.ID = table2.SubID
FOR XML AUTO, XMLDATA";
and
DataSet data = new DataSet();
DbCommand cmd = conn.CreateCommand();
cmd.CommandText = SQL;
data.ReadXml(((System.Data.SqlClient.SqlCommand)cmd).ExecuteXmlReader(),
xmlReadMode.Fragment);
that's it
来源:https://stackoverflow.com/questions/5326703/read-multiple-tables-with-relations-with-t-sql-into-dataset