我已经构建了一个 xml/aspx 页面,该页面通过 sql server 检索产品表中的所有行。此页面用作 xmlfeed。此 xml 显示产品详细信息,如名称、价格和库存等。因为查询非常耗时,我只想检索已更改的行(例如库存)。在sql server中解决这个问题的方法是什么?
sql服务器
select name,price,productid
from product
C#
public List<Feed> GetFeed()
{
DataSet dst = new DataSet();
SqlCommand cmd = null;
List<Feed> feedlist = new List<Feed>();
using (SqlConnection conn = new SqlConnection(connectionstring))
{
conn.Open();
cmd = new SqlCommand("[GetFeed]", conn);
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataReader rs = cmd.ExecuteReader())
{
while (rs.Read())
{
feed feed = new Feed();
feed.productID = rs["ProductID"].ToString();
feed.price = rs["price"].ToString();
feedlist.Add(feed);
}
rs.NextResult();
}
}
return feedlist;
}
public class Feed
{
public string Price { get; set; }
public string Name { get; set; }
public string ProductID { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
var feeds = GetFeed();
XElement products =
new XElement("products",
from p in feeds
select new XElement("Product",
new XElement("id", p.ProductID),
new XElement("Price", p.Price),
new XElement("Name", p.Name)
)
);
Response.ContentType = "text/xml";
Response.Write(products.ToString());
Response.End();
}