我又来了 新问题有出现了
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 = "";
}
将 varchar 值 '19;' 转换为数据类型为 int 的列时发生语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 将 varchar 值 '19;' 转换为数据类型为 int 的列时发生语法错误。
源错误:
行 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