下面的代码有问题,请帮助解决,title,content不能进行更新
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 localhost
{
/// <summary>
/// huifu 的摘要说明。
/// </summary>
public class huifu : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink login;
protected System.Web.UI.WebControls.TextBox title;
protected System.Web.UI.WebControls.TextBox content;
protected System.Web.UI.WebControls.TextBox Textbox1;
protected System.Web.UI.WebControls.Button Button1;
    public int id;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (Request.Cookies["UserName"]!=null)
{
login.Text="<a href='pass.aspx'><img src=images/pass.gif border=0></a>&nbsp;&nbsp;&nbsp;<a href='default.aspx'><img src=images/ysxx.gif border=0></a>&nbsp;&nbsp;&nbsp;<a href='logout.aspx'><img src=images/logout.gif border=0></a>";
}
else 
{
login.Text="<img src=images/login.gif border=0>";
login.NavigateUrl="login.aspx";
} id=int.Parse(Request.QueryString["id"].ToString()); SqlConnection nwindConn = new SqlConnection((string)Application["sqlConn"]);
SqlCommand selectCMD = new SqlCommand("SELECT * FROM gbdb where id ='"+id+"'", nwindConn);
selectCMD.CommandTimeout = 30;
nwindConn.Open();
SqlDataReader objReader = selectCMD.ExecuteReader();
DataGrid dgData = new DataGrid();
dgData.DataBind();
while(objReader.Read())
{
title.Text=objReader["title"].ToString();
content.Text=objReader["content"].ToString();
}
objReader.Close();
nwindConn.Close();
}
private void QiuGou_Inster()
{
string title1=title.Text.Trim();
string content1=content.Text.Trim();
string Textbox1s=Textbox1.Text.Trim(); SqlConnection huifuConn = new SqlConnection((string)Application["sqlConn"]);
huifuConn.Open();
SqlCommand insertCMD = new SqlCommand("update gbdb set title='"+title1+"',content='"+content1+"',huifu='"+Textbox1s+"' where id ='"+id+"' ", huifuConn);
insertCMD.CommandTimeout = 30;
insertCMD.ExecuteNonQuery();
huifuConn.Close(); Response.Redirect("admin.aspx"); }
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
this.QiuGou_Inster();
Button1.Enabled=false; }
}
}

解决方案 »

  1.   

    SqlCommand insertCMD = new SqlCommand("update gbdb set title='"+title1+"',content='"+content1+"',huifu='"+Textbox1s+"' where id ="+id, huifuConn);
      

  2.   

    参考:
    string strsql;
    strsql="update  zxhc88_user "+"set Zxhc88_bs=1 "+"where Zxhc88_ID="+e.Item.Cells[0].Text;
      

  3.   

    最忌讳的错误:没写 if (!Page.IsPostBack),
      

  4.   

    我可以肯定不是SQL错误,因为,能读能写,就是修改被读出的字段不好使
      

  5.   

    建议:在Page_Load中,加上
    if (!Page.IsPostBack)
    {
        //你的初始化代码
    }取得Id后,将Id用ViewState保存。
    public int id{
      get{ if( ViewState["_Id"] == null )
              ViewState["_Id"] = 0;
              return (int)ViewState["_Id"];
          }
      set {  ViewState["_Id"] = value; }
    }
      

  6.   

    同意chinagy(会员GY) ,因为我们的页面在不断的刷新,你如果不加入if (!Page.IsPostBack)语句,在刷新的时候,你的输入会被刷新的结果覆盖