哪位好心的大虾帮我看下这段代码哪错了啊。..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;
using System.Data.SqlClient;public partial class Ex09_05 : System.Web.UI.Page
{
    protected SqlConnection myConnection = new SqlConnection();    protected void BindData()
    { 
        //留言者的留言情况
        string selCmd1 = "select * from Ex09_GuestBook where PostID="+postID;
        SqlDataAdapter da1 = new SqlDataAdapter(selCmd1, myConnection);
        //留言者的所有回复者情况
        string selCmd2 = "select * from Ex09_GuestBook where ParentID="+postID;
        SqlDataAdapter da2 = new SqlDataAdapter(selCmd2, myConnection);
        DataSet ds = new DataSet();
        da1.Fill(ds, "host");
        da2.Fill(ds, "guest");
        //留言者的主题
        Label1.Text = ds.Tables["host"].Rows[0][4].ToString();
        //留言者的回复次数
        int reCount = ds.Tables["guest"].Rows.Count;
        Label2.Text = reCount.ToString();
        //留言者的发表时间
        Label3.Text = ds.Tables["host"].Rows[0][2].ToString();
        //留言内容
        Label4.Text = ds.Tables["host"].Rows[0][4].ToString();
        //留言的作者,并将作者的UserName作为参数传到Ex09_06.aspx
        HyperLink1.Text = ds.Tables["host"].Rows[0][3].ToString();
        HyperLink1.NavigateUrl = "Ex09_06.aspx?UserName=" + HyperLink1.Text;
        //绑定数据
        DataList1.DataSource = ds;
        DataList1.DataMember = "guest";
        DataList1.DataBind();
        this.DataBind();
        myConnection.Close();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Count == 0)//访问者未登陆
            Response.Redirect("Ex09_01.aspx");
        else//访问者已登陆
        {            if (!IsPostBack)
            {
                postID = Request["PostID"];                string strConn = "server=localhost;uid=sa;pwd=;database=Aspnet";
                myConnection.ConnectionString = strConn;
                BindData();
            }
        }
    }
    protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
    {    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {    }
    protected void DataList1_SelectedIndexChanged1(object sender, EventArgs e)
    {    }
}
下面是错误消息:
D:\C#\WebSite1\Ex09_05.aspx.cs(20,71): 错误 CS0103: 当前上下文中不存在名称“postID”
D:\C#\WebSite1\Ex09_05.aspx.cs(23,73): 错误 CS0103: 当前上下文中不存在名称“postID”
D:\C#\WebSite1\Ex09_05.aspx.cs(56,17): 错误 CS0103: 当前上下文中不存在名称“postID”

解决方案 »

  1.   

    很明显嘛,搂主postID = Request["PostID"]; 中的postID 未定义
      

  2.   

    搂主加个定义就行了:
    string postID = Request["PostID"]; 
      

  3.   

    呵呵。..加了后解决了一个D:\C#\WebSite1\Ex09_05.aspx.cs(20,71): 错误 CS0103: 当前上下文中不存在名称“postID” 
    D:\C#\WebSite1\Ex09_05.aspx.cs(23,73): 错误 CS0103: 当前上下文中不存在名称“postID”
    还有两个。..郁闷了
      

  4.   

    呵呵。..加了后解决了一个 D:\C#\WebSite1\Ex09_05.aspx.cs(20,71): 错误 CS0103: 当前上下文中不存在名称“postID” 
    D:\C#\WebSite1\Ex09_05.aspx.cs(23,73): 错误 CS0103: 当前上下文中不存在名称“postID” 
    还有两个。..郁闷了
      

  5.   

    看来搂主的postID使模块全局变量搂主这里:
        protected void BindData() 
        { 
            //留言者的留言情况 
            string selCmd1 = "select * from Ex09_GuestBook where PostID="+postID; 
    改成:
        private string postID = "";
        protected void BindData() 
        { 
            //留言者的留言情况 
            string selCmd1 = "select * from Ex09_GuestBook where PostID="+postID; 然后把我4楼说的修改给撤销回去,也就是说把:string postID = Request["PostID"]; 
    还原成postID = Request["PostID"]; 就可以了