当前位置:编程学习 > C#/ASP.NET >>

asp.net修改代码问题

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;

public partial class administrator_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] != null)
            {
                this.binddata();
            }
            else
            {
                Response.Redirect("loginin.aspx");
            }
        }
    }

    protected void binddata()
    {
        if (Request.QueryString["id"].ToString() != null)
        {
            int hid = Convert.ToInt32(Request.QueryString["id"].ToString().Trim());
            string strsql = string.Format("select * from jiazhiqixi where id={0}", hid);
            DataSet ds = Helper.ExecuteDataSet(strsql);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                this.txtNewsTitle.Text = dr["title"].ToString();
                this.FCKeditor1.Value = dr["content"].ToString();
                Response.Write(dr["title"].ToString());
            }
        }

    }

    private void updatadata()
    {
        int id = Convert.ToInt32(Request.QueryString["id"].ToString().Trim());
        string title = this.txtNewsTitle.Text;
        string content = this.FCKeditor1.Value;
        string strsql12 = string.Format("update jiazhiqixi set title='{0}'',content='{1}' where id={2}", title, content, id);
        try
        {
            Helper.ExecuteNonQuery(strsql12);
            Response.Write("<script>alert('修改成功')</script>");
            Response.Write("<script>location.href='jiazhiqixi.aspx'</script>");
        }
        catch
        {
            Response.Write("<script>alert('请确定你编辑的内容')</script>");
        }  
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["id"].ToString().Trim() != null)
        {
            updatadata();
            Response.Redirect("jiazhiqixi.aspx");
        }       
    }
}可以得到文件,但是修改不成功!麻烦各位帮忙看看

追问:额晕,大意,谢谢了
答案:        string strsql12 = string.Format("update jiazhiqixi set title='{0}'',content='{1}' where id={2}", title, content, id);

 

        string strsql12 = string.Format("update jiazhiqixi set title='{0}',content='{1}' where id={2}", title, content, id);

 

看看是不是这出错了。

Helper.ExecuteNonQuery(strsql12);这句代码应该有返回值吧,定义个变量接收一下返回值,在此行插入断点,调试一下,看看提示什么错误
 if (!IsPostBack)改成 if (IsPostBack)试试

上一个:ASP 修改数据代码~~求高手!!
下一个:ASP用户注册后台SQL代码问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,