极度困惑,下面的程序怎么会是这样的结果?!
一个以DataGrid显示邮票品种的ASP.net页面,在DataGrid中以一个HyperlinkColumn来用一个链接删除某个品种(将状态置为无效):
<%@ Page Language=C# Trace=false %>
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Data.OleDb " %>
<Script language= "C# " runat= "server ">
public void Page_Load(Object sender, EventArgs e){
if (!Page.IsPostBack){
BindGrid();
}
}
public void DBItemEdit(Object sender,DataGridCommandEventArgs e){
DBGrid.EditItemIndex=e.Item.ItemIndex;
BindGrid();
}
public void DBItemCancel(object sender,DataGridCommandEventArgs e){
DBGrid.EditItemIndex=-1;
BindGrid();
}
public void DBItemUpdate(object sender,DataGridCommandEventArgs e){
string StrStampNO =e.Item.Cells[0].Text;
string CnnString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+Server.MapPath( "Stamp.MDB ");
OleDbConnection cnn = new OleDbConnection(CnnString);
StringBuilder Sb=new StringBuilder( "Select * from Stamp Where State=1 and StampNO= ");
Sb.Append(StrStampNO);
DataSet Ds=new DataSet();
OleDbDataAdapter Adapter=new OleDbDataAdapter(Sb.ToString(),cnn);
OleDbCommandBuilder Cb=new OleDbCommandBuilder(Adapter);
Adapter.Fill(Ds, "Stamp ");
DataRow Dr=Ds.Tables[ "Stamp "].Rows[0];
TextBox txtModStampName=(TextBox)e.Item.Cells[1].Controls[0];
TextBox txtModAmount=(TextBox)e.Item.Cells[2].Controls[0];
TextBox txtModStampClassID=(TextBox)e.Item.Cells[3].Controls[0];
Dr[ "StampName "]=txtModStampName.Text;
Dr[ "Amount "]=txtModAmount.Text;
Dr[ "StampClassID "]=txtModStampClassID.Text;
Adapter.Update(Ds, "Stamp ");
DBGrid.EditItemIndex=-1;
BindGrid();
}
public void BindGrid(){
string CnnString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+Server.MapPath( "Stamp.MDB ");
OleDbConnection cnn = new OleDbConnection(CnnString);
StringBuilder Sb=new StringBuilder( "select * from Stamp Where State=1 order by StampClassID ");
OleDbDataAdapter Da=new OleDbDataAdapter(Sb.ToString(),cnn);
DataSet Ds=new DataSet();
cnn.Open();
Da.Fill(Ds, "ResTable ");
DBGrid.DataSource=Ds.Tables[ "ResTable "].DefaultView;
DBGrid.DataBind();
cnn.Close();
lblMsg.Text= " ";
}
public void BtnAddNew_Click(object sender, EventArgs e){
string CnnString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+Server.MapPath( "Stamp.MDB ");
OleDbConnection cnn = new OleDbConnection(CnnString);
string StrSql= "Select * from Stamp ";
DataSet Ds=new DataSet();
OleDbDataAdapter Adapter=new OleDbDataAdapter(StrSql,cnn);
OleDbCommandBuilder Cb=new OleDbCommandBuilde