我有这张桌子: ID | FILE
1 | ROOT> ELEMENT TYPE =“DATABASE”CNNSTR =“Data Source =(local); Initial Catalog = testForDLL; Integrated Security = SSPI; Persist Security Info = False;” QUERY =“SELECT * FROM TBL1 WHERE id = 1”/> ROOT>
2 | ROOT ELEMENT TYPE =“DATABASE”CNNSTR =“Data Source =(local); Initial Catalog = testForDLL; Integrated Security = SSPI; Persist Security Info = False;” QUERY =“SELECT * FROM TBL2 WHERE id = 1”/> ROOT>
我想从第二列加载值并用它创建一个XDOCUMENT。 到目前为止我有这个代码:
using (SqlConnection conn = new SqlConnection(cnnstr))
{
conn.Open();
SqlCommand com = conn.CreateCommand();
com.CommandText = "SELECT [FILE] FROM XML_Config WHERE id=" + id;
XDocument doc2 = new XDocument();
XmlReader dtRead = com.ExecuteXmlReader();
if (dtRead.Read())
doc2.Load(dtRead); -> This line has an error
}
问你想要什么,以便帮助我。
答案 0 :(得分:0)
我想我用这段代码解决了这个问题。
using (SqlConnection conn = new SqlConnection(cnnstr))
{
string xmlstr;
conn.Open();
SqlCommand com = conn.CreateCommand();
com.CommandText = "SELECT [FILE] FROM XML_Config WHERE id=" + id;
SqlDataReader dtRead = com.ExecuteReader();
while (dtRead.Read())
xmlstr= dtRead.GetSqlString(0).ToString();
XDocument docBD = XDocument.Parse(xmlstr);
return docBD;
}
你认为这是最好的解决方案吗?