【问题标题】:ORA-01006 : bind variable does not exist ASP.NETORA-01006: 绑定变量不存在 ASP.NET
【发布时间】:2014-11-23 06:08:38
【问题描述】:

我是 ASP.NET 编码的新手,所以如果我遗漏了一些明显的东西,请原谅我。

我正在编写一个数据输入页面,其中我有一个 FormView 设置为默认插入来处理插入,我有一个 gridview 来查看表中的数据并允许编辑。

gridview 的编辑效果很好,但是 FormView 让我失望了。 当我在 FormView 中点击插入时,我得到一个 ORA-01006:绑定变量不存在。

我使用的 SQLDataSource 指向一个 Oracle DB。

我的 FormView 代码是:

<asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="DATAKEY" DataSourceID="Oracle" DefaultMode="Insert" ForeColor="#333333" HorizontalAlign="Left">

        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <InsertItemTemplate>
         <table>
         <tr>
             <td align="center">Year :</td>
             <td width="30px"><asp:TextBox ID="YearTextBox" runat="server" Text='<%# Bind("YEAR") %>'></asp:TextBox><br /></td>
         </tr>
          <tr>
             <td align="center">Week :</td>
             <td width="30px"><asp:TextBox ID="WeekTextBox" runat="server" Text='<%# Bind("WEEK") %>'></asp:TextBox><br /></td>
         </tr>
          <tr>
             <td align="center">Store :</td>
             <td width="30px"><asp:TextBox ID="StoreTextBox" runat="server" Text='<%# Bind("LOC_LOC_ID") %>'></asp:TextBox><br /></td>
         </tr>
         <tr>
             <td align="center">Brand :</td>
             <td width="30px"><asp:TextBox ID="BrandTextBox" runat="server" Text='<%# Bind("BRAND") %>'></asp:TextBox><br /></td>
         </tr>
          <tr>
             <td align="center">CO_WK_PERC :</td>
             <td width="30px"><asp:TextBox ID="CoWkPercTextBox" runat="server" Text='<%# Bind("CO_WK_PERC") %>'></asp:TextBox><br /></td>
         </tr>
          <tr>
             <td align="center">CO_STD_PERC :</td>
             <td width="30px"><asp:TextBox ID="CoStdPercTextBox" runat="server" Text='<%# Bind("CO_STD_PERC") %>'></asp:TextBox><br /></td>
         </tr>
          <tr>
             <td align="center">INT_WK_PERC :</td>
             <td width="30px"><asp:TextBox ID="IntWkPercTextBox" runat="server" Text='<%# Bind("INT_WK_PERC") %>'></asp:TextBox><br /></td>
         </tr>
          <tr>
             <td align="center">INT_STD_PERC :</td>
             <td width="30px"><asp:TextBox ID="IntStdPercTextBox" runat="server" Text='<%# Bind("INT_STD_PERC") %>' Enabled='<%# Bind("INT_STD_PERC") %>'></asp:TextBox><br /></td>
         </tr>
         </table>
            <div class="auto-style1">
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </div>
        </InsertItemTemplate>

        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    </asp:FormView>

我的 SQLDataSource 是:

<asp:SqlDataSource ID="Oracle" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:ORACLE_IISUSER %>" 
        DeleteCommand="DELETE FROM &quot;RGP_PLAN_PERC_TEST_BK&quot; WHERE &quot;DATAKEY&quot; = ?" 
        InsertCommand="INSERT INTO &quot;RGP_PLAN_PERC_TEST_BK&quot; (&quot;YEAR&quot;, &quot;WEEK&quot;, &quot;BRAND&quot;, &quot;CO_WK_PERC&quot;, &quot;CO_STD_PERC&quot;, &quot;INT_WK_PERC&quot;, &quot;INT_STD_PERC&quot;, &quot;LOC_LOC_ID&quot;, &quot;DATAKEY&quot;) VALUES (:YEAR, :WEEK, :BRAND, :CO_WK_PERC, :CO_STD_PERC, :INT_WK_PERC, :INT_STD_PERC, :LOC_LOC_ID, (SELECT (MAX(DATAKEY) +1) FROM RGP_PLAN_PERC_TEST_BK) )" 
        ProviderName="<%$ ConnectionStrings:ORACLE_IISUSER.ProviderName %>" 
        SelectCommand="SELECT * FROM &quot;RGP_PLAN_PERC_TEST_BK&quot; ORDER BY &quot;YEAR&quot; DESC, &quot;WEEK&quot; DESC, &quot;LOC_LOC_ID&quot;" 
        UpdateCommand="UPDATE &quot;RGP_PLAN_PERC_TEST_BK&quot; SET &quot;YEAR&quot; = :YEAR, &quot;WEEK&quot; = :WEEK, &quot;BRAND&quot; = :BRAND, &quot;CO_WK_PERC&quot; = :CO_WK_PERC, &quot;CO_STD_PERC&quot; = :CO_STD_PERC, &quot;INT_WK_PERC&quot; = :INT_WK_PERC, &quot;INT_STD_PERC&quot; = :INT_STD_PERC, &quot;LOC_LOC_ID&quot; = :LOC_LOC_ID WHERE &quot;DATAKEY&quot; = :DATAKEY" OnSelecting="Oracle_Selecting">
        <DeleteParameters>
            <asp:Parameter Name="DATAKEY" Type="Decimal" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="YEAR" Type="String" />
            <asp:Parameter Name="WEEK" Type="String" />
            <asp:Parameter Name="BRAND" Type="String" />
            <asp:Parameter Name="CO_WK_PERC" Type="Decimal" />
            <asp:Parameter Name="CO_STD_PERC" Type="Decimal" />
            <asp:Parameter Name="INT_WK_PERC" Type="Decimal" />
            <asp:Parameter Name="INT_STD_PERC" Type="Decimal" />
            <asp:Parameter Name="LOC_LOC_ID" Type="String" />
            <asp:Parameter Name="DATAKEY" Type="Decimal" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="YEAR" Type="String" />
            <asp:Parameter Name="WEEK" Type="String" />
            <asp:Parameter Name="BRAND" Type="String" />
            <asp:Parameter Name="CO_WK_PERC" Type="Decimal" />
            <asp:Parameter Name="CO_STD_PERC" Type="Decimal" />
            <asp:Parameter Name="INT_WK_PERC" Type="Decimal" />
            <asp:Parameter Name="INT_STD_PERC" Type="Decimal" />
            <asp:Parameter Name="LOC_LOC_ID" Type="String" />
            <asp:Parameter Name="DATAKEY" Type="Decimal" />
        </UpdateParameters>
    </asp:SqlDataSource>

不知道是不是因为我没有正确链接FormView参数?

我希望有人能对我的问题有所了解?

亲切的问候

汤姆

【问题讨论】:

    标签: c# sql asp.net oracle


    【解决方案1】:

    ORA-01006 : bind variable does not exist 错误的意思是在您的代码中某处正在构造参数化 SQL 语句,但是您调用该语句时您传递的参数不够多或传递给许多参数。

    仔细看,我发现你的

    DeleteCommand="DELETE FROM &quot;RGP_PLAN_PERC_TEST_BK&quot; WHERE &quot;DATAKEY&quot; = ?" 
    

    没有参数
    它应该看起来像:

    DeleteCommand="DELETE FROM &quot;RGP_PLAN_PERC_TEST_BK&quot; WHERE &quot;DATAKEY&quot; = :DATAKEY" 
    

    Oracle documentation

    程序对未在 关联的 SQL 语句。只有那些以 a 为前缀的变量 SQL 语句中的冒号 (:) 或与号 (&) 可以在 BIND 调用,OBIND 或 OBINDN。此错误也可能是由 预编译器程序和相关库之间的不匹配, SQLLIB。

    【讨论】:

      【解决方案2】:

      BindByName 不是默认值,必须明确设置:

      conn.ConnectionString = 
       ConfigurationManager.ConnectionStrings("somedb").ConnectionString)
      conn.Open()
      Dim ocmd = conn.CreateCommand()
      ocmd.BindByName = True
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-29
        • 2011-08-06
        • 1970-01-01
        • 2014-12-16
        • 1970-01-01
        • 2019-07-01
        • 2012-06-21
        相关资源
        最近更新 更多