让我们风风火火的过一生,别平平淡淡过一年。
没有关闭数据库的原因。
[此贴子已经被作者于2006-4-18 18:46:43编辑过]
private void datatomonmentsource()
{
OleDbConnection con=DBConn.createConn();
con.Open();
OleDbDataAdapter oda=new OleDbDataAdapter();
oda.SelectCommand=new OleDbCommand("select monmentID,productID,numofproduct,priceofproduct,usercount from monmentgood",con);
DataSet ds=new DataSet();
oda.Fill(ds,"monment");
this.DataGrid1.DataKeyField="monmentID";
this.DataGrid1.DataSource=ds.Tables["monment"].DefaultView;
this.DataGrid1.DataBind();
con.Close();//增加这一句
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string userID=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
string usernum=((TextBox)e.Item.Cells[1].Controls[0]).Text;
OleDbConnection con=DBConn.createConn();
con.Open();
OleDbCommand cmd=new OleDbCommand("update monmentgood set numofproduct="+Convert.ToInt32(usernum)+" where monmentID="+Convert.ToInt32(userID),con);
cmd.ExecuteNonQuery();
this.DataGrid1.EditItemIndex=-1;
con.Close();//增加这一句
this.datatomonmentsource();
}