//用DataSet更新数据库
protected void md(int id, string fild, string value)
{
//int id 要更新数据的ID,fild要更新的字段,value更新后的值
string strSQL = "SELECT * FROM i_user where uid="+id;
OleDbDataAdapter myODA = new OleDbDataAdapter(strSQL, DataAccess.GetStrConn());
OleDbCommandBuilder myCommandBuilder = new OleDbCommandBuilder(myODA);
DataSet myDS = new DataSet();
myODA.FillSchema(myDS, SchemaType.Source, "i_user");
myODA.Fill(myDS, "i_user");
DataTable tbl = myDS.Tables[0];
tbl.PrimaryKey = new DataColumn[] { tbl.Columns["uid"] };
DataRow myRow = tbl.Rows.Find(id);
myRow[fild] = value; //如果要更新多个字段,就在这里加吧
myODA.Update(myDS, "i_user");
myDS.AcceptChanges();
Label1.Text = myDS.Tables["i_user"].Rows[0].ToString();
this.ld();
}
//绑定到GridView上
protected void ld()
{
GridView1.PageIndex = 1;
GridView1.DataSource = DataAccess.dataSet("SELECT uid,uname FROM i_user order by uid desc");
this.GridView1.DataBind();
}