日期:2010-10-18  浏览次数:20593 次

数据库采用SQL Server 2005 Express Edition, 数据库构造就不说了。
SQL语句: SELECT title, keywords, description FROM PageInfo WHERE (url= @url)SqlDataSource,名字为sds
具体的代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Header_cs : System.Web.UI.MasterPage {
  protected void Page_Load(object sender, EventArgs e) {

    sds.SelectParameters.Add("url",
      Request.AppRelativeCurrentExecutionFilePath);
    IDataReader reader =
      (IDataReader)sds.Select(new DataSourceSelectArguments());

    if (reader.Read()) {
      Page.Header.Title = reader.GetString(0);
      HtmlMeta meta1 = new HtmlMeta();
      HtmlMeta meta2 = new HtmlMeta();
      meta1.Name = "keywords";
      meta1.Content = reader.GetString(1);
      meta2.Name = "description";
      meta2.Content = reader.GetString(2);
      Page.Header.Controls.Add(meta1);
      Page.Header.Controls.Add(meta2);
    }
  }
}