在SQL2005中增加了xml类型数据。这样,我们可以将我们应用程序中的实体对象直接保存到数据库中。下次要取的时候就可以直接将XML反序列化成实体对象。对于数据量不是很大的情况下,可以考虑使用。
select * from Employee
where [content].exist(''//Age[text()>9000]'')=1
此SQL语句中带有xpath的查询,可以找出employee表中content为XML类型列中子节点>9000的所有记录
看一下,运用.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml.Serialization;
using System.IO;
namespace DevTest
{
public partial class Form3 : Form
{
SqlConnection cn = new SqlConnection("server=192.168.1.100\\SqlExpress;uid=hpasc;pwd=9637004;database=filemanager");
public Form3()
{
InitializeComponent();
cn.Open();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = cn.GetSchema();
this.dataGridView1.DataSource = dt;
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = cn.GetSchema("Tables",null);
this.dataGridView1.DataSource = dt;
}
private void button3_Click(object sender, EventArgs e)
{
//this.dataGridView1.DataSource = cn.GetSchema("IndexColumns", new string[] { "FileManager", "dbo", "Creers" });
SqlCommand cmd = new SqlCommand();
List<Employee> Emps = new List<Employee>();
cmd.CommandText = "insert into Employee values(@OID,@Name,@Age,@City,@Address,@Birthday,@Content)";
XmlSerializer ser = new XmlSerializer(typeof(Employee));
&nbs |