求助GridView不能更新
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using weblibrary.data;
public partial class _Default : System.Web.UI.Page
{
private SqlDataAdapter da;
private DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
getInfo();
}
private void getInfo()
{
string str = "Data Source = .;Initial Catalog = library; User Id = sa;Password = 123";
string sql = "select * from LB_FLXX";
SqlConnection conn = new SqlConnection(str);
da = new SqlDataAdapter(sql, conn);
da.Fill(ds, "t");
GridView1.DataSource = ds.Tables["t"];
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
getInfo();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(ds, "t");
GridView1.EditIndex = -1;
getInfo();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
getInfo();
}
}