从数据库中取出的内容放入freetextbox中然后更新,发现数据库中freetextbox的内容见了.
我已经加入了if(!IsPostBack).
我把代码放在下面,请高手们指教.
 int i=int.Parse(Request.QueryString["qid"].ToString().Trim());
string sql="select id,title,content,times,author,source,type,image,cishu from news where (id="+i+")";
            SqlConnection connection1=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["data"]); 
if(!IsPostBack)
{
try
{
SqlCommand command1=new SqlCommand(sql,connection1);
SqlDataReader reader1;
connection1.Open();
reader1=command1.ExecuteReader();
if(reader1.Read())
{

box1.Text=reader1["title"].ToString();
box2.Text=reader1["author"].ToString();
box3.Text=reader1["source"].ToString();
FreeTextBox1.Text=reader1["content"].ToString();
} }
catch(Exception ex) 
{
throw (ex);
}
finally
{
connection1.Close();
}
} } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.button2.Click += new System.Web.UI.ImageClickEventHandler(this.button2_Click);
this.button11.Click += new System.Web.UI.ImageClickEventHandler(this.button11_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void button2_Click(object sender, System.Web.UI.ImageClickEventArgs e)

SqlConnection connection1=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["data"]); 
// if(!IsPostBack)
// {
try
{
int i=int.Parse(Request.QueryString["qid"].ToString().Trim());
string titles=box1.Text.ToString();
string authors=box2.Text.ToString();
string sources=box3.Text.ToString();
string newss=FreeTextBox1.Text.ToString();
string sql="UPDATE news SET [title]=@title,[author]=@author,[source]=@source,[content]=@content where (id="+i+")";
SqlCommand command1=new SqlCommand(sql,connection1);
command1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@title", System.Data.SqlDbType.VarChar, 50, "title"));
command1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@author", System.Data.SqlDbType.VarChar, 50, "author"));
command1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@source", System.Data.SqlDbType.VarChar, 50, "source"));
command1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@content", System.Data.SqlDbType.NText, 16, "content"));
command1.Parameters["@title"].Value=box1.Text.ToString();
command1.Parameters["@author"].Value=box2.Text.ToString();
command1.Parameters["@source"].Value=box3.Text.ToString();
command1.Parameters["@content"].Value=FreeTextBox1.Text.ToString();

connection1.Open();
command1.ExecuteNonQuery();
//box1.Text=null;
//box2.Text=null;
//box3.Text=null;
// FreeTextBox1.Text=null;
//string titless=dataoperate.title(box1);
// Response.Write(titless);
}
catch (Exception ex)
{
throw (ex);
}
finally
{
connection1.Close();
}
// }  
}

解决方案 »

  1.   

    这里是.NET高级群,在内的都是有一定水平的成员,请大家一起来探讨!   3945892
      

  2.   

    不知道你在button2_Click()事件里面加入if(!IsPostBack)是干什么的,不过你应该知道页面的执行顺序是先Page_Load()后执行具体触发PostBack的事件,页面刷新后Page_Load事件总是会先执行。
    不过我觉得你的问题没有说清楚,“从数据库中取出的内容放入freetextbox中然后更新,发现数据库中freetextbox的内容见了.”,我不太明白是什么意思。