夜步十里松原阅读答案:懂ASP.NET DataList的来

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 12:29:45
我写好如下 还是无法更新数据TextBox2里面本来是120-119122
后把他改为 119-123456
单步调试穿进去的还是TextBox2值120-119122,怎么才能更新成119-123456
public void DataList1_UpdateCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{ TextBox txtLastName = (TextBox)e.Item.FindControl( "TextBox2" );
SqlConnection con =new SqlConnection("server=localhost;uid=sa;pwd=sa;Database=pubs");
string str="update authors set phone=@phone Where au_lname='White'";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Parameters.Add("@phone",txtLastName.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataList1.EditItemIndex = -1;
BindDataList();
}