寫入資料庫的XML欄位型態

  • 4116
  • 0
  • C#
  • 2016-06-29

摘要:寫入資料庫的XML欄位型態

XmlTextReader XMLTR = new XmlTextReader(@"C:\Users\ken.huang\Desktop\40.xml");
    string str="";
    while (XMLTR.Read())
    {
    switch (XMLTR.NodeType)
    {
    case XmlNodeType.Element:
    str += "<"+XMLTR.Name+">";
    break;
    case XmlNodeType.Text:
    str += XMLTR.Value;
    break;
    case XmlNodeType.EndElement:
    str += "</"+XMLTR.Name+">";
    break;

    }
    }
    SqlParameter para = new SqlParameter("@xml",str);
    para.DbType= System.Data.DbType.Xml;