【问题标题】:ORA-01036: illegal variable name/number while adding paramater to an oracle commandORA-01036: 向 oracle 命令添加参数时变量名称/编号非法
【发布时间】:2013-10-01 10:53:02
【问题描述】:

由于某种原因,每当我尝试执行页面时,下面的代码都会返回 ORA-01036:非法变量名称/编号。我尝试删除它读取 cmd.BindByName = true 的部分,它返回另一个错误,该错误并非所有变量绑定。以下是我的代码:

try
{
    int row;
    DataSet dataset = new DataSet();

    OracleCommand cmd = new OracleCommand(sql, conn);

    for (row = 0; row < gvParameters.Rows.Count; row++)
    {                    
        TextBox text = (TextBox)gvParameters.Rows[row]
            .FindControl("txtParamValue");
        cmd.Parameters.Add(gvParameters.Rows[row].Cells[1].Text, text.Text);
    }
    cmd.BindByName = true;

    OracleDataAdapter adapter = new OracleDataAdapter();
    adapter.SelectCommand = cmd;
    adapter.Fill(dataset);

    if (conn.State == ConnectionState.Open)
    {
        conn.Close();
        conn.Dispose();
    }

    gvResults.DataSource = dataset.Tables[0];
    gvResults.DataBind();
}
catch (Exception ex)
{
    X.MessageBox.Alert("Information", ex.ToString()).Show();
    conn.Close();
    conn.Dispose();
}

这是我正在使用的查询。

SELECT
    *
FROM
(
  SELECT
    ROW_NUMBER() OVER (ORDER BY NULL) AS No
    , cspOutput.*   
  FROM   
  (     
  SELECT DISTINCT *
FROM
(

SELECT DISTINCT 
      wl.specname
      ,wep.paramnamename dataname
      ,wep.paramvalue || ' - ' || NVL(ht.name, ' ') datavalue
      ,wep.paramsequence
      ,e.employeename
      ,e.fullname
      --,'WIP' AS Type
      ,we.equipmentname
      ,we.trackinemployeename      
      ,c.containername
FROM container c
JOIN a_wiplot wl ON wl.containerid = c.containerid
JOIN a_wiplotdetails wld ON wl.wiplotid = wld.wiplotid
JOIN a_wiplotdetailswafers wldw ON wld.wiplotdetailsid = wldw.wiplotdetailsid
JOIN a_wipequipment we ON we.containerid = wl.containerid
JOIN a_wipequipmentparams wep ON we.wipequipmentid= wep.wipequipmentid
LEFT JOIN otherdb.hw_inventory ht ON wep.paramvalue = ht.BARCODE
LEFT JOIN employee e ON we.trackinemployeename = e.employeename
WHERE c.containername = ?lotID AND wep.paramvalue IS NOT NULL
UNION ALL
SELECT DISTINCT 
      hml.specname
      ,wep.paramnamename dataname
      ,wep.paramvalue || ' - ' || NVL(ht.name, ' ')  datavalue
      ,wep.paramsequence
      ,e.employeename
      ,e.fullname
      --,'TrackInOut' AS Type
      ,we.equipmentname      
      ,we.trackinemployeename      
      ,c.containername
FROM container C
JOIN a_wipequipmenthistory we ON c.containerid = we.containerid OR c.splitfromid  = we.containerid
JOIN historymainline HML on hml.historysummaryid = we.wipequipmentlinkid AND (hml.historyid = c.containerid OR hml.historyid = c.splitfromid)
JOIN a_wipequipmentparamshistory wep ON wep.wipequipmenthistoryid = we.wipequipmenthistoryid
LEFT JOIN otherdb.hw_inventory ht ON wep.paramvalue = ht.BARCODE
LEFT JOIN employee e ON we.trackinemployeename = e.employeename
WHERE c.containername = ?lotID AND wep.paramvalue IS NOT NULL
) 
)cspOutput
)
WHERE No BETWEEN (((?BLOCKOF200ROWS - 1) * 200) + 1) AND (?BLOCKOF200ROWS * 200)

感谢大家的帮助。

【问题讨论】:

  • 您可以尝试检查 gvParameters.Rows[row].Cells[1].Texttext.Text 进入该 Add 函数。
  • social.msdn.microsoft.com/Forums/en-US/… - 请注意提供此错误的大约 5 个不同原因的答案。
  • 您尝试插入的 SQL 语句和参数名称和值是什么?
  • @Damith 我已经更新了我的问题,谢谢。
  • @muratgu 我得到了正确的参数名称和值。当我绑定它时,就是它出错的时间。

标签: c# asp.net oracle11g


【解决方案1】:

我的错。原来我传递了不正确的数据。很抱歉提出这个问题。当我将所有变量都放在我的观察列表中时,我感到很困惑。我没有输入 0,而是输入了 1。现在它正在工作。谢谢:)

【讨论】:

    猜你喜欢
    • 2013-01-06
    • 2011-10-05
    • 1970-01-01
    • 2014-11-12
    • 2020-07-29
    • 2016-04-03
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    相关资源
    最近更新 更多