Help, a big problem worried me for week!!

Last post 05-14-2007 8:41 AM by Sohnee. 1 replies.

Sort Posts:

  • Help, a big problem worried me for week!!

    05-13-2007, 11:16 PM
    • Member
      30 point Member
    • iamybj
    • Member since 10-26-2006, 7:32 AM
    • Shandong Province, China
    • Posts 11

    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();
    				}
    
    				...
    
    			}
    		}
     
  • Re: Help, a big problem worried me for week!!

    05-14-2007, 8:41 AM
    Answer
    • Contributor
      2,560 point Contributor
    • Sohnee
    • Member since 02-02-2007, 5:18 PM
    • UK
    • Posts 492

    Here are a few possible reasons:

    1) One of your parameter names might be more than 32 characters long - which causes this error.

    2) You've ommitted the : from the front of the parameter names in the parameter collection.

    3) You've got a [space] at the end of one of your parameter names

    4) You need to clear the parameters from previous use before you set these (i.e. an old parameter from your select is still hanging about)

    I've included all of these to help out other people that come across the same problem. You're particular problem should be solved with this (Oracle is a bit different to MSSQL in this respect):

         this.cmd.Parameters.Add(":dydm",OracleType.VarChar,4).Value = dydm;
         this.cmd.Parameters.Add(":ny",OracleType.VarChar,6).Value = ny;

     

    Filed under: ,
Page 1 of 1 (2 items)