我有下面的数据集,该数据集正在生成我需要的所有表,现在我正在将该信息写入XML文件。我遇到的问题是我还没有弄清楚如何动态检索信息。例如,每个ClaimLines节点将具有多个子代,而这些子代也将具有子代。使用数据集该怎么做?我为每个循环都尝试了一个,但Visual Studio返回了错误。
DataSet ds = new DataSet("ClinicalEdit");
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["dbc"]))
{
SqlCommand sqlComm = new SqlCommand("ClinicalEditing20_2.clinicalEditLoad_EXRACT", conn);
sqlComm.Parameters.AddWithValue("@clinicalEdit_ID", clinicalEdit_id);
sqlComm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlComm;
da.Fill(ds);
XDocument clinicalEdit = new XDocument();
new XElement("externalEditClaim",
new XElement("hccClaimNumber", "12345")
new XElement("claimLines","???This is the step I cannot figure Out
}
更新: 我可能已经找到了一种方法,方法是使ClaimLines的值调用类似下面的方法。这似乎可行,但是在将其称为解决方案之前,我需要尝试再上一个或两个级别。
public XElement[] getClaimLines(DataSet ds)
{
var result = new List<XElement>();
foreach (DataRow row in ds.Tables[1].Rows)
{
result.Add(new XElement(new XElement("claimLine",
new XElement("hccLineNumber", row["hccLineNumber"].ToString()))));
}
return result.ToArray();
}
查看我的更新。我创建的方法就像一个魅力。