public void dataBd()
{
OleDbDataAdapter da = new OleDbDataAdapter("select * from xxb",conn);
conn.Open();
da.Fill(ds,"xxb");
conn.Close();
GridView1.DataSource = ds.Tables["xxb"];
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
dataBd();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
GridView1.EditIndex = Convert.ToInt32(e.CommandArgument);
dataBd();
}
if (e.CommandName == "Update")
{
string sqlStr = "update xxb set xh='" + ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Controls[0]).Text + "' , xm='" + ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[3].Controls[0]).Text + "' where ID=" + GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
OleDbCommand comUd = new OleDbCommand(sqlStr, conn);
conn.Open();
comUd.Prepare();
comUd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
dataBd();
}
}
}