现在我正在尝试提供一些服务,我可以在其中读取 xml 文件并将其解析为 sql server,我已经阅读并看到许多教程如何使用 c# 将 xml 解析为 sql server,但我仍然无法获取数据。
<?xml version="1.0" encoding="utf-8" ?>
<Source 1 - Subject 17>
SubjectType: Faces
FaceConfidence: 100
<appeared at 02/08/2018 5:28:43 PM>
FrameIndex: 1033
Rectangle: at (210;169), width=63, height=84
</appeared at 02/08/2018 5:28:43 PM>
<track at 02/08/2018 5:28:44 PM>
FrameIndex: 1050
Rectangle: at (210;134), width=70, height=94
<Details available on frame 1050>
FrameIndex: 1050
Status: Ok
Eyes at: (260; 169) and (229; 169)
Rectangle: at (210;134), width=70, height=94
</Details available on frame 1050>
</track at 02/08/2018 5:28:44 PM>
<disappeared at 02/08/2018 5:28:46 PM>
TimeStamp: 02/08/2018 5:28:46 PM
<Top 1000 of Best Matches>
no matches found
</Top 1000 of Best Matches>
Contains successfully generated template
</disappeared at 02/08/2018 5:28:46 PM>
</Source 1 - Subject 17>
这是 xml 文件格式,这是我的尝试:
protected void Button1_Click(object sender, EventArgs e)
{
string cs = @"Data Source=172.16.6.39;Initial Catalog=FC_SCAN;Persist Security Info=True;User ID=fc_adm;Password=P@ssw0rd";
SqlConnection con = new SqlConnection(cs);
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
var source = doc.DocumentElement.SelectNodes("Source").Cast<XmlElement>().ToList();
var appeared = source[0].GetAttribute("Appeared");
var disappeared = source[0].GetAttribute("Disappeared");
var top = source[0].GetAttribute("Top");
SqlCommand cmd;
SqlDataAdapter da = new SqlDataAdapter();
string sql = null;
con.Open();
sql = "Insert into Source values ('" + source + "','" + appeared + "','" + disappeared + "','"+top+"')";
cmd = new SqlCommand(sql, con);
da.InsertCommand = cmd;
da.InsertCommand.ExecuteNonQuery();
con.Close();
}
错误控制台总是出现在 xml 文件中,我非常感谢任何帮助、技巧或提示。
森林海
红糖糍粑
慕慕森
相关分类