protected void btnSumit_Click(object sender, EventArgs e)
{
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
string path = Server.MapPath("db.xml");
XmlDocument xml = new XmlDocument();
xml.Load(path);
XmlNodeList node = xml.GetElementsByTagName("Item");
foreach (XmlElement n in node)
{
cmd.CommandText = string.Format("insert into img2(title,content,creatTime) values('"+n.GetAttribute("title")+"','"+n.GetAttribute("Content")+"','"+n.GetAttribute("CreatTime")+"')");
cmd.ExecuteNonQuery();
}
}
conn.Close();
}
XML结构:
<?xml version="1.0" standalone="yes"?>
<Group>
<Item title="今天" Content="今天心情很好" CreatTime="2010-5-27 14:34:37" />
<Item title="好" Content="好心情" CreatTime="2010-5-31 17:23:45" />
<Item title="zxczx" Content="zxczxc" CreatTime="2010-5-31 17:34:25" />
<Item title="as" Content="asdasdasd" CreatTime="2010-6-2 11:14:08" />
<Item title="sadfsa" Content="sfdsfdsadxcvzxvc" CreatTime="2010-6-2 11:30:03" />
<Item title="oijd" Content="你好" CreatTime="2010-6-2 11:39:01" />
<Item title="好心情" Content="今天是个好日子" CreatTime="2010-6-3 16:44:58" />
</Group>
注:(字段区分大小写 如:CreatTime)