首页上一页 1 下一页尾页 1 条记录 1/1页
ASP.NET 2.0网络编程自学手册 一书中 ch07_01例子的疑问
发表在ASP.NET图书答疑
2009-12-19
是否精华
是
否
版块置顶:
是
否
protected void Page_Load(object sender, EventArgs e)
{
this.aa();
}
public void aa()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=;database=stu;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from student";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
sda.Fill(ds, "student");
con.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
///这是插入
if (this.TextBox1.Text == "" && this.TextBox2.Text == "" && this.TextBox3.Text == "")
{
Response.Write("<script language=javascript>alert('信息不能为空,请必须全部填写!')</script>");
}
else
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=;database=stu;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into student values(" + this.TextBox1.Text + ",'" + this.TextBox2.Text + "','" + this.TextBox3.Text + "')";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
protected void Button4_Click(object sender, EventArgs e)
{
///这是刷新
//this.aa();
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=;database=stu;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from student";
cmd.Connection = con;
con.Open();
}
///偶的疑问是为啥Button4_Click中没有使用 datasource,databind,也没有调用page_load里面的aa,却能够刷新gridview1?
只是打开了一个连接,就能刷新gridview1?????
为啥同样执行Button1_Click,却不能刷新gridview1????非要再执行Button4_Click才行??????
{
this.aa();
}
public void aa()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=;database=stu;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from student";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
sda.Fill(ds, "student");
con.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
///这是插入
if (this.TextBox1.Text == "" && this.TextBox2.Text == "" && this.TextBox3.Text == "")
{
Response.Write("<script language=javascript>alert('信息不能为空,请必须全部填写!')</script>");
}
else
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=;database=stu;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into student values(" + this.TextBox1.Text + ",'" + this.TextBox2.Text + "','" + this.TextBox3.Text + "')";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
protected void Button4_Click(object sender, EventArgs e)
{
///这是刷新
//this.aa();
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=;database=stu;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from student";
cmd.Connection = con;
con.Open();
}
///偶的疑问是为啥Button4_Click中没有使用 datasource,databind,也没有调用page_load里面的aa,却能够刷新gridview1?
只是打开了一个连接,就能刷新gridview1?????
为啥同样执行Button1_Click,却不能刷新gridview1????非要再执行Button4_Click才行??????