ç¨urlåæ°ä¼ éåï¼ç½ä¸å¥½å¤é½æ¯è¿æ ·åç
æ¯å¦ä½ 主页index.aspxä¸å ç¯çé¾æ¥å°åå¯ä»¥åæï¼
<a href="Shown.asp?id=2">第ä¸ç¯</a>
<a href="Shown.asp?id=3">第äºç¯</a>
<a href="Shown.asp?id=5">第ä¸ç¯</a>
è®°çï¼ä¸é¢çé¾æ¥æ¯ä½ æ ¹æ®æ°æ®åºä¿¡æ¯å¨æçæç idåé¢çæ°åæ¯ä½ æç« è¡¨ä¸çç¼å·å段ï¼å¦æä½ æ°æ®è¡¨æ²¡æè¿ä¸ªå段ï¼å»ºè®®å ä¸ä¸ä¸ªèªå¨ç¼å·å段ï¼ç¨æ é¢çè¯ä¸è½ä½ä¸ºå¯ä¸æ è¯ï¼
ç¶åä½ å¯ä»¥å¨ä½ çshown.aspxè¿æ ·å
åå°ç±»ä¼¼è¿æ ·ï¼ä½ æFormä¸çå¤å¶è¿ä½ çFormä¸ï¼
<form id="Form1" runat="server">
<asp:Label id="ArticleTitle" runat="server"/>
<BR><BR>
<asp:Label id="ArticleContent" runat="server"/>
</form>
åå°ï¼è¿éåªæä¾Accessæ°æ®åºçå®ç°ï¼
protected void Page_Load(object sender, EventArgs e)
{
string id=Request.QueryString["id"]
if (id!="")
{
string sqlstr = "select * from æç« è¡¨ where id="+id;
string ConnString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=ä½ Accessæ件çè·¯å¾"; //å¦ææ¯SqlServeræ°æ®åºï¼èªå·±ççæ¹æ¹è¿éåä¸é¢ç代ç
OleDbConnection conn = new OleDbConnection(ConnString);
OleDbCommand comm = new OleDbCommand();
comm.Connection = conn;
comm.CommandText=sqlstr;
conn.Open();
OleDbDataReader reader =comm.ExecuteDataReader();
if(reader.Read())
{
this.ArticleTitle.Text=reader["æç« æ é¢å段å"].ToString();
this.ArticleContent.Text=reader["æç« å
容å段å"].ToString();
}
else
{
Response.Write("没ææ¾å°ç¸å
³æ°æ®");
}
reader.Close();
conn.Close();
}
}
å¦æä½ æ¯SqlServeræ°æ®åº
string sqlstr = "select * from æç« è¡¨ where id="+id;
string ConnString = @"Data Source=.\sqlexpress;Initial Catalog=DataBaseName;Integrated Security=True";
SqlConnection conn = new SqlConnection(ConnString);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText=sqlstr;
conn.Open();
SqlDataReader reader=comm.ExecuteReader();
ä¸é¢ä»£ç åä¸é¢ä¸æ ·
温馨提示:内容为网友见解,仅供参考