I have a simple web page to show a table. And I can delete each row by clicking the delete button behind each row.
But it don't work. When !Page.IsPostBack, the table shows correctly, but when i click the delete button, the page posts back, then occurs "ORA-01036: illegal variable name/number".
This is the methods to fill the datagrid:
1 private void dgTableDataBind(string dwdm, string qsny, string zzny)
2 {
3 string sqlSelect = @"select rowid, dydm dwdm, kgsdm2mc(dydm) dwmc, ny, decode(passed, 1, '是', '否') passed from yjbg_zb_yyfx_dxjy where ny between :qsny and :zzny and dydm like :dwdm order by ny desc";
4 this.cmd.CommandText = sqlSelect;
5 this.cmd.Parameters.Add("qsny", OracleType.VarChar, 6).Value = qsny;
6 this.cmd.Parameters.Add("zzny", OracleType.VarChar, 6).Value = zzny;
7 this.cmd.Parameters.Add("dwdm", OracleType.VarChar, 4).Value = dwdm;
8 this.cmd.CommandType = CommandType.Text;
9 this.cmd.Connection = this.con;
10 this.adp.SelectCommand = this.cmd;
11 try
12 {
13 this.adp.Fill(this.ds, "dgTable");
14 }
15 catch(Exception ex)
16 {
17 this.lblTabelMsg.Text += "填充数据集时出错:" + ex.Message + "<br>";
18 return;
19 }
20 this.dgTable.DataSource = this.ds;
21 this.dgTable.DataMember = "dgTable";
22 this.dgTable.DataBind();
23 }
24
25 private void dgTableDataBind()
26 {
27 this.dgTableDataBind(this.ddlDW.SelectedItem.Value, this.hdQSNY.Value, this.hdZZNY.Value);
28 }
29
......
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
if(!Page.IsPostBack)
{
...
this.dgTableDataBind("%", year + "01", year + month);
...
}
}
WHEN DELETE:
private void dgTable_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string cmdnm = e.CommandName;
string dydm = e.Item.Cells[6].Text;
string ny = ((Label)e.Item.FindControl("lblNY")).Text;
...
if(cmdnm == "DELETE")
{
string sqlDelete = "delete from yjbg_zb_yyfx_dxjy where dydm = :dydm and ny = :ny";
this.cmd.CommandText = sqlDelete;
this.cmd.Parameters.Add("dydm",OracleType.VarChar,4).Value = dydm;
this.cmd.Parameters.Add("ny",OracleType.VarChar,6).Value = ny;
this.cmd.CommandType = CommandType.Text;
this.cmd.Connection = this.con;
if(this.con.State == ConnectionState.Closed)
{
this.con.Open();
}
try
{
this.cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
this.lblTabelMsg.Text += ex.Message + "<br>";
}
finally
{
this.con.Close();
}
this.dgTableDataBind();
}
...
}
}