private void 学生界面_Load(object sender, EventArgs e)
{
string connstr = "Server=.;database=Student1;uid=sa;pwd=xld158";
SqlConnection connection = new SqlConnection(connstr);//数据库连接实例
connection.Open();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand b = new SqlCommand("select name,number,sex,phone,sic,ability from StuMess where userid='" + d + "'", connection);
da.SelectCommand = b;
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
label8.Text = dt.Rows[f]["name"].ToString();
label9.Text = dt.Rows[f]["number"].ToString();
label10.Text = dt.Rows[f]["sex"].ToString();
label11.Text = dt.Rows[f]["phone"].ToString();
label12.Text = dt.Rows[f]["sic"].ToString();
label13.Text = dt.Rows[f]["ability"].ToString();
connection.Close();
}
public 密码修改界面()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
学生界面 form2 = new 学生界面();
form2.Show();
this.Close();
}
每次请求页面,都会执行对应页面的page_load,作为page_load的局部变量的dt,自然每次都需要重新填充一次,之前的无效