viewstate页面传值问题!!!
public partial class buy_buy_add : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.Text = "YLRK" + year + month + day + hour + minute + second;
ViewState["1"] = this.TextBox2.Text.ToString();
this.TextBox3.Text = this.ViewState["1"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
string serialNumber = this.ViewState["1"].ToString();
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlTransaction st = strcon.BeginTransaction();
SqlCommand sc = strcon.CreateCommand();
sc.Transaction=st;
try
{
sc.CommandText = "insert into tb_commodity_more(serialNumber)values('"+serialNumber+"')";
sc.ExecuteNonQuery();
st.Commit();
Response.Write("<script language=javascript>alert('添加成功');location='buy_add.aspx'</script>");
}
catch(Exception error)
{
st.Rollback();
Response.Write("<script language=javascript>alert('添加失败');location='buy_add.aspx'</script>");
}
}
}
关键程序如上所示,Textbox3可以显示viewstate的数值,但是数据库写不进去啊,事务回滚,显示添加失败,请高手帮忙看一下!!!!
--------------------编程问答-------------------- //ViewState["1"] = this.TextBox2.Text.ToString(); --------------------编程问答-------------------- this.TextBox1.Text = "YLRK" + year + month + day + hour + minute + second;
ViewState["1"] = this.TextBox1.Text.ToString();
this.TextBox3.Text = this.ViewState["1"].ToString();
有点笔误,高手马上明白的
补充:.NET技术 , ASP.NET