C# ORA-01036:向oracle命令添加paramater时变量名/编号非法

C# ORA-01036:向oracle命令添加paramater时变量名/编号非法,c#,asp.net,oracle11g,C#,Asp.net,Oracle11g,出于某种原因,每当我尝试执行页面时,下面的代码都会返回ORA-01036:非法变量名/编号。我尝试删除读取cmd.BindByName=true的部分,它返回另一个错误,该错误不完全是变量绑定的。下面是我的代码: try { int row; DataSet dataset = new DataSet(); OracleCommand cmd = new OracleCommand(sql, conn); for (row = 0; row < gvPa

出于某种原因,每当我尝试执行页面时,下面的代码都会返回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();
}

谢谢你们的帮助。

我的错。结果表明我传递的数据不正确。很抱歉提起这件事。当我把所有变量都放在观察列表上时,我感到困惑。我没有输入0,而是输入了1。现在它正在工作。谢谢:)

您可以尝试检查
gvParameters.Rows[row].Cells[1]。Text
Text.Text
进入该
Add
函数。-请注意答案,该答案提供了导致此错误的5种不同原因。您尝试插入的SQL语句、参数名称和值是什么?@Damith我已更新了我的问题,谢谢。@muratgu我得到的参数名称和值恰到好处。当我绑定它时,就是它出错的时间。
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)