using System;  
using System.Collections;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Web;  
using System.Web.SessionState;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.HtmlControls;  
using System.Data.SqlClient;  
namespace liuyanban  
{  
   ///  <summary>  
   /// huifu 的摘要说明。  
   ///  </summary>  
   public class huifu : System.Web.UI.Page  
   {  
      protected System.Web.UI.WebControls.Label Label4;  
      protected System.Web.UI.WebControls.Label Label1;  
      protected System.Web.UI.WebControls.HyperLink HyperLink1;  
      protected System.Web.UI.WebControls.Label Label2;  
      protected System.Web.UI.WebControls.DataList DataList1;  
      protected System.Web.UI.WebControls.TextBox TextBox1;  
      protected System.Web.UI.WebControls.Button Button1;  
      protected System.Web.UI.WebControls.Button Button2;  
      protected System.Web.UI.WebControls.Label Label3;  
      protected SqlConnection myconnection=new SqlConnection();  
     
      private void Page_Load(object sender, System.EventArgs e)  
      {  
         if (Session.Count==0)  
            Response.Redirect("denglu.aspx");  
         else  
         {  
            if(!IsPostBack)  
             {postid=Request["postid"];              }  
            myconnection.ConnectionString="server=deant;uid=sa;pwd=sa;database=bbs";  
            BindData();  
         }  
      }  
      private void BindData()  
      {string selcmd1="select * from guestbook where postid="+postid;  
        SqlDataAdapter da1=new SqlDataAdapter(selcmd1,myconnection);  
         string selcmd2="select * from guestbook where postid="+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();  
         HyperLink1.Text=ds.Tables["host"].Rows[0][3].ToString();  
            HyperLink1.NavigateUrl="liuyanzhe.aspx?username="+HyperLink1.Text;  
         DataList1.DataSource=ds;  
            DataList1.DataMember="guest";  
            DataList1.DataBind();  
         this.DataBind();  
         myconnection.Close();  
      }  
         private void Button2_Click(object sender, System.EventArgs e)  
      {  
         string name=Session["username"].ToString();  
         string inscmd="insert guestbook values("+postid+",gerdate(),'"+name+"','','"+Textbox2.Text+"')";  
         SqlCommand mycmd=new SqlCommand(inscmd,myconnection);  
         mycmd.Connection.Open();  
         mycmd.ExecuteNonQuery();  
         mycmd.Connection.Close();  
         BindData();  
         TextBox1.Text="";  
      }        private void Button1_Click(object sender, System.EventArgs e)  
      {  
      TextBox1.Text="";  
      }          
   }  
}  
上面是全部代码,现在的问题是回复和重写按钮都不能用  点击后都会出现相同错误
即:第 1 行: '=' 附近有语法错误。    
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。    异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。   源错误:    
行 51:          SqlDataAdapter da2=new SqlDataAdapter(selcmd2,myconnection);      
行 52:             DataSet ds=new DataSet();   
行 53:          da1.Fill(ds,"host");   
行 54:          da2.Fill(ds,"guest");   
行 55:          Label1.Text=ds.Tables["host"].Rows[0][4].ToString();   
    源文件: c:\inetpub\wwwroot\liuyanban\huifu.aspx.cs    行: 53    
“/liuyanban”应用程序中的服务器错误  
主要是回复贴出错

解决方案 »

  1.   

     
    if (Session.Count==0) 
    {  
                Response.Redirect("denglu.aspx"); 
    }  
             else   
             {   
                if(!IsPostBack)   
                 {postid=Request["postid"];               }   
                myconnection.ConnectionString="server=deant;uid=sa;pwd=sa;database=bbs";   
                BindData();   
             }   
      

  2.   


    string inscmd="insert guestbook values("+postid+",gerdate(),'"+name+"','','"+Textbox2.Text+"')";   
    gerdate()应该为getdate()
      

  3.   

    string selcmd1="select * from guestbook where postid='"+postid+"'"; string selcmd2="select * from guestbook where postid='"+postid+"'";试试看看行不行啊 ?   
      

  4.   

    private void Page_Load(object sender, System.EventArgs e)   
          {   
             if (Session.Count==0)   
                Response.Redirect("denglu.aspx");   
             else   
             {   
                if(!IsPostBack)   
                 {
                   //postid=Request["postid"];               }   
                myconnection.ConnectionString="server=deant;uid=sa;pwd=sa;database=bbs";   
                BindData();   
             }  
      private void BindData()
        {
            string strcmd1 = "select * from GuestBook where PostID="+Request["PostID"];
            SqlDataAdapter da1 = new SqlDataAdapter(strcmd1,myConnection);
            string strcmd2 = "select * from GuestBook where ParentID="+Request["PostID"];        SqlDataAdapter da2 = new SqlDataAdapter(strcmd2,myConnection);
            DataSet ds = new DataSet();
            da1.Fill(ds,"host");
            da2.Fill(ds,"guest");
            Lbltitle00.Text = ds.Tables["host"].Rows[0][4].ToString(); //留言的主题
            int recount = ds.Tables["guest"].Rows.Count;//回复的次数
            lbltimes00.Text = recount.ToString();
            lblwritetime00.Text = ds.Tables["host"].Rows[0][2].ToString();//留言的时间
            lblcontent.Text = ds.Tables["host"].Rows[0][5].ToString();//留言的 内容
            HyperLink1.Text = ds.Tables["host"].Rows[0][3].ToString();//留言的作者
            HyperLink1.NavigateUrl = "authorinfo.aspx?UserName=" + HyperLink1.Text; //将作者作为参数传到author.aspx
            DataList1.DataSource = ds;
            DataList1.DataMember = "guest";
            DataList1.DataBind();
            myConnection.Close();
        }
        protected void Btnsubmit_Click(object sender, EventArgs e)
        {
            string name = Session["UserName"].ToString();
            string inscmd = "insert into GuestBook values('"+Request["PostID"]+"',getdate(),'"+name+"',' ','"+Txtresponse.Text+"')";
            SqlCommand myCommand = new SqlCommand(inscmd,myConnection);
            myCommand.Connection.Open();
            myCommand.ExecuteNonQuery();
            myCommand.Connection.Close();
            myConnection.Close();
            BindData();
            Txtresponse.Text = "";
        }
        protected void Btnrewrite_Click(object sender, EventArgs e)
        {
            Txtresponse.Text = "";
        }
      

  5.   

    修改string strcmd1 = "select * from GuestBook where PostID="+Request["PostID"]; 
            SqlDataAdapter da1 = new SqlDataAdapter(strcmd1,myConnection); 
            string strcmd2 = "select * from GuestBook where ParentID="+Request["PostID"]; 
    重写按钮好用 但是回复按钮不行  错误如下:
    第 1 行: ',' 附近有语法错误。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: ',' 附近有语法错误。源错误: 
    行 83:  SqlCommand mycmd=new SqlCommand(inscmd,myconnection);
    行 84:      mycmd.Connection.Open();
    行 85:  mycmd.ExecuteNonQuery();
    行 86:  mycmd.Connection.Close();
    行 87:  myconnection.Close();
     源文件: c:\inetpub\wwwroot\liuyanban\huifu.aspx.cs    行: 85 
    如果改成
    private void Button2_Click(object sender, System.EventArgs e)   
          {   
             string name=Session["username"].ToString();   
             string inscmd="insert guestbook values("+Request["PostID"]+",gerdate(),'"+name+"','','"+Textbox2.Text+"')";   
             SqlCommand mycmd=new SqlCommand(inscmd,myconnection);   
             mycmd.Connection.Open();   
             mycmd.ExecuteNonQuery();   
             mycmd.Connection.Close();   
             BindData();   
             TextBox1.Text="";   
          }   
    那么显示第 1 行: ';' 附近有语法错误。其他一样  怎么回事?