protected void Button1_Click(object sender, EventArgs e)
{
if (Session["username"] == "您还没有登录")
{
this.Page.RegisterStartupScript("ss", "<script>alert('您还没有登录,请您登录后再回帖')</script>");
}
else
{
if (TextBox2.Text == "" || TextBox4.Text == "")
{
this.Page.RegisterStartupScript("ss", "<script>alert('请输入回复评论的标题和内容')</script>");
return;
}
else
{
//判断输入的验证码是否正确
string num = this.TextBox3.Text.Trim();
if (Session["ValidNums"].ToString() == num.ToUpper())
{
// 连接数据库
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon.Open();
//获得回复数量
string strselect1 = "select * from tb_forums where id='" + Request["id"]+ "'";
SqlCommand sqlcmd1 = new SqlCommand(strselect1, sqlcon);
SqlDataReader dr1 = sqlcmd1.ExecuteReader();
int hfnums = 0;
if (dr1.Read()) ///////这里出现错误//////////
{
hfnums = Convert.ToInt32(dr1["hf_nums"].ToString()) + 1;
}
dr1.Close();
//更改主表中的回复数量
string Strupdate = "update tb_forums set hf_nums=" + hfnums + " where id='" + Request["id"].ToString() + "'";
SqlCommand cmd = new SqlCommand(Strupdate, sqlcon);
cmd.ExecuteNonQuery();
//向子表中插入数据
string StrInserts = "insert into tb_Sub_forums(forumid,styleid,title,contents,dates,authorid,first_forum) values(@forumid,@styleid,@title,@contents,@dates,@authorid,0)";
SqlCommand cmds = new SqlCommand(StrInserts, sqlcon);
// 添加参数并且设置参数值
cmds.Parameters.Add("@forumid", SqlDbType.VarChar);
cmds.Parameters["@forumid"].Value = Request["id"].ToString();
cmds.Parameters.Add("@styleid", SqlDbType.VarChar);
cmds.Parameters["@styleid"].Value = GetStyleId(Session["forumstyle"].ToString()).ToString();
cmds.Parameters.Add("@title", SqlDbType.VarChar);
cmds.Parameters["@title"].Value = this.TextBox4.Text.ToString();
cmds.Parameters.Add("@contents", SqlDbType.VarChar);
cmds.Parameters["@contents"].Value = this.TextBox2.Text.ToString();
cmds.Parameters.Add("@dates", SqlDbType.VarChar, 50);
cmds.Parameters["@dates"].Value = DateTime.Now.ToString();
cmds.Parameters.Add("@authorid", SqlDbType.VarChar);
cmds.Parameters["@authorid"].Value = Session["userid"].ToString();
// 执行插入数据的操作
cmds.ExecuteNonQuery();
sqlcon.Close();
this.Page.RegisterStartupScript("ss", "<script>alert('恭喜您,成功回帖!')</script>");
}
else
{
this.Page.RegisterStartupScript("ss", "<script>alert('您输入的验证码不正确!')</script>");
}
}
}
}
{
if (Session["username"] == "您还没有登录")
{
this.Page.RegisterStartupScript("ss", "<script>alert('您还没有登录,请您登录后再回帖')</script>");
}
else
{
if (TextBox2.Text == "" || TextBox4.Text == "")
{
this.Page.RegisterStartupScript("ss", "<script>alert('请输入回复评论的标题和内容')</script>");
return;
}
else
{
//判断输入的验证码是否正确
string num = this.TextBox3.Text.Trim();
if (Session["ValidNums"].ToString() == num.ToUpper())
{
// 连接数据库
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon.Open();
//获得回复数量
string strselect1 = "select * from tb_forums where id='" + Request["id"]+ "'";
SqlCommand sqlcmd1 = new SqlCommand(strselect1, sqlcon);
SqlDataReader dr1 = sqlcmd1.ExecuteReader();
int hfnums = 0;
if (dr1.Read()) ///////这里出现错误//////////
{
hfnums = Convert.ToInt32(dr1["hf_nums"].ToString()) + 1;
}
dr1.Close();
//更改主表中的回复数量
string Strupdate = "update tb_forums set hf_nums=" + hfnums + " where id='" + Request["id"].ToString() + "'";
SqlCommand cmd = new SqlCommand(Strupdate, sqlcon);
cmd.ExecuteNonQuery();
//向子表中插入数据
string StrInserts = "insert into tb_Sub_forums(forumid,styleid,title,contents,dates,authorid,first_forum) values(@forumid,@styleid,@title,@contents,@dates,@authorid,0)";
SqlCommand cmds = new SqlCommand(StrInserts, sqlcon);
// 添加参数并且设置参数值
cmds.Parameters.Add("@forumid", SqlDbType.VarChar);
cmds.Parameters["@forumid"].Value = Request["id"].ToString();
cmds.Parameters.Add("@styleid", SqlDbType.VarChar);
cmds.Parameters["@styleid"].Value = GetStyleId(Session["forumstyle"].ToString()).ToString();
cmds.Parameters.Add("@title", SqlDbType.VarChar);
cmds.Parameters["@title"].Value = this.TextBox4.Text.ToString();
cmds.Parameters.Add("@contents", SqlDbType.VarChar);
cmds.Parameters["@contents"].Value = this.TextBox2.Text.ToString();
cmds.Parameters.Add("@dates", SqlDbType.VarChar, 50);
cmds.Parameters["@dates"].Value = DateTime.Now.ToString();
cmds.Parameters.Add("@authorid", SqlDbType.VarChar);
cmds.Parameters["@authorid"].Value = Session["userid"].ToString();
// 执行插入数据的操作
cmds.ExecuteNonQuery();
sqlcon.Close();
this.Page.RegisterStartupScript("ss", "<script>alert('恭喜您,成功回帖!')</script>");
}
else
{
this.Page.RegisterStartupScript("ss", "<script>alert('您输入的验证码不正确!')</script>");
}
}
}
}
解决方案 »
- ◤急◥如何在页面上显示JS的日期控件!!!
- 未将对象引用设置到实例
- 光标移动到超链接时显出子表信息详情!
- 在.aspx页面中调用JS文件中的函数报错:缺少对象?????
- .net 讀取無規則EXCEL
- 怎么隐藏登陆框
- 我使用TabStrip和Multipage,但是我不能放Web控件在PageView中,请问怎么回事?
- 使用webClient.UploadFile上传文件时,总是提示 远程服务器返回错误:(404)未找到。
- 用JS如何动态删除table中的tbody?
- 想要一个在datagrid中update数据的源代码
- VS2010运行网站一直白屏无限加载
- asp.net里的GridView控件怎么样指定每一列的宽度
string Strupdate = "update tb_forums set hf_nums=" + hfnums + " where id=" + Request["id"].ToString() ;其他地方也是类似
forumid是VarChar类型?
如果你搞不懂类型,你及直接写
cmds.Parameters.AddWithValue("@forumid", Request["id"].ToString());
不要指定类型