您的位置:首页 > 其它

textbox.text被赋值后无法得到用户重新输入的内容--[低级错误忘记在 Page_Load()里面加if (!IsPostBack) ]

2007-10-30 16:03 363 查看
今天不知是头晕,还是长期使用vs自带数据控件的诟病,一个低级错误搞了半小时!晕

错误代码:

protected void Page_Load(object sender, EventArgs e)

{

try

{

TextBoxTitle.Text = ConnectToDataBase.GetOnResutFronSqlServer(ConfigurationManager.ConnectionStrings ["yongchengConnectionString"].ConnectionString, "select title from cooperate");

TextBoxContext.Text = ConnectToDataBase.GetOnResutFronSqlServer(ConfigurationManager.ConnectionStrings["yongchengConnectionString"].ConnectionString, "select context from cooperate");

}

catch (Exception ex)

{

TextBoxContext.Text = "读取数据时失败,请尝试刷新页面重新链接到数据库!";

TextBoxTitle.Enabled = false;

TextBoxTitle.Enabled = false;

}

}

protected void Button1_Click(object sender, EventArgs e)

{

using (SqlConnection cn = new SqlConnection())

{

cn.ConnectionString = ConfigurationManager.ConnectionStrings["yongchengConnectionString"].ConnectionString;

using (SqlCommand cmd = new SqlCommand())

{

cmd.Connection = cn;

cmd.CommandText = "update cooperate set title=@title,context=@context where id=1";

cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value = TextBoxTitle.Text.ToString();

cmd.Parameters.Add("@context", SqlDbType.NVarChar).Value = TextBoxContext.Text;

cn.Open();

cmd.ExecuteScalar();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐