已经设置过 !IsPostBack if (IsPostBack) { //实例化Connection对象 using (connection = new SqlConnection("Data Source=.;Initial Catalog=classnewssystem;Persist Security Info=True;User ID=sa;Password=123")) {//实例化Command对象 using (SqlCommand command = new SqlCommand("select * from Information where Sname=@SName", connection)) { command.Parameters.AddWithValue("@SName", "小小"); adapter = new SqlDataAdapter(command); data = new DataTable();
if (!IsPostBack)
{ }
if (IsPostBack)
{
//实例化Connection对象
using (connection = new SqlConnection("Data Source=.;Initial Catalog=classnewssystem;Persist Security Info=True;User ID=sa;Password=123"))
{//实例化Command对象
using (SqlCommand command = new SqlCommand("select * from Information where Sname=@SName", connection))
{
command.Parameters.AddWithValue("@SName", "小小");
adapter = new SqlDataAdapter(command);
data = new DataTable();
adapter.Fill(data);
data.PrimaryKey = new DataColumn[] { data.Columns["Sno"] };
data.Rows[0].BeginEdit();
data.Rows[0]["Sno"] = number.Text;
data.Rows[0]["Sname"] = name.Text;
data.Rows[0]["Ssex"] = sex.Text;
data.Rows[0]["Sage"] =this.age.Text;
data.Rows[0].EndEdit();
data.AcceptChanges();
adapter.Update(data);
}
}
}
{
//实例化Connection对象
using (connection = new SqlConnection("Data Source=.;Initial Catalog=classnewssystem;Persist Security Info=True;User ID=sa;Password=123"))
{//实例化Command对象
using (SqlCommand command = new SqlCommand("select * from Information where Sname=@SName", connection))
{
command.Parameters.AddWithValue("@SName", "小小");
adapter = new SqlDataAdapter(command);
data = new DataTable();
adapter.Fill(data);
data.PrimaryKey = new DataColumn[] { data.Columns["Sno"] };
this.number.Text = data.Rows[0]["Sno"].ToString(); name.Text = data.Rows[0]["Sname"].ToString();
sex.Text = data.Rows[0]["Ssex"].ToString();
age.Text = data.Rows[0]["Sage"].ToString();
}
}再次重新声明!IsPostBack 和IsPostBack的情况都写了,运行时修改的值返回页面时有显示,就是数据库没有更新,调试时textbox显示值已经改变
command.Parameters.AddWithValue("@SName", "小小");
adapter = new SqlDataAdapter(command); data.PrimaryKey = new DataColumn[] { data.Columns["Sno"] };
this.number.Text = data.Rows[0]["Sno"].ToString(); name.Text = data.Rows[0]["Sname"].ToString();
sex.Text = data.Rows[0]["Ssex"].ToString();
age.Text = data.Rows[0]["Sage"].ToString();
data = new DataTable();
adapter.Fill(data);这样试试
adapter.Update(data); 有写更新