3

我在下面收到此错误:

ORA-01036: 非法变量名称/编号。

该错误仅在单击更新或删除时发生(所有文本框必须完整才能使更新生效)。我最终从 SQL 数据库更改为 Oracle 数据库,但我一直在这里和那里遇到一些小问题。编辑和取消一行工作正常。下面我将包括我的查询:

protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "Insert") //- this is needed to explain that the INSERT command will only work when INSERT is clicked
        {
            gv.DataBind();

            DataTable d = dbcon.GetDataTable("SELECT * FROM CIS.CIS_TRANS ORDER BY ID DESC", "ProjectCISConnectionString");

            string transCode = "", fundCode = "", BSA_CD = "", DP_TYPE = "";

            if (d.Rows.Count > 0)
            {
                transCode = d.Rows[0]["TRANS_CD"].ToString();
                fundCode = d.Rows[0]["FUND_CD"].ToString();
                BSA_CD = d.Rows[0]["BSA_CD"].ToString();
                DP_TYPE = d.Rows[0]["DP_TYPE"].ToString();

                if (transCode.Trim().Length > 0)
                {
                    dbcon.Execute("INSERT INTO CIS.CIS_TRANS (ID,TRANS_CD) VALUES(CIS.S_CIS_TRANS.nextval,'')", "ProjectCISConnectionString");

                    gv.DataBind();
                }
            }

            gv.EditIndex = gv.Rows.Count - 1;

        }
        else if (e.CommandName == "Cancel")
        {
            DataTable d = dbcon.GetDataTable("SELECT * FROM CIS.CIS_TRANS ORDER BY ID DESC", "ProjectCISConnectionString");

            string transCode = "";

            if (d.Rows.Count > 0)
            {
                transCode = d.Rows[0]["TRANS_CD"].ToString();

                if (transCode.Trim().Length == 0)
                {
                    dbcon.Execute(string.Format("DELETE CIS.CIS_TRANS WHERE ID = '{0}'", d.Rows[0]["ID"]), "ProjectCISConnectionString");

                    gv.DataBind();
                }
            }

如果你们需要我包含我的代码的其他部分,请随意说。我将立即将其包括在内。

下面是我的源代码:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ProjectCISConnectionString %>" ProviderName="<%$ConnectionStrings:ProjectCISConnectionString.ProviderName %>"
            SelectCommand="SELECT * FROM CIS.CIS_TRANS ORDER BY ID ASC" 
            DeleteCommand="DELETE FROM CIS.CIS_TRANS WHERE ID = @ID"
            InsertCommand="INSERT INTO CIS.CIS_TRANS (TRANS_CD,FUND_CD,BSA_CD,DP_TYPE,TRANS_CD_DESC) VALUES (@TRANS_CD,@FUND_CD,@BSA_CD,@DP_TYPE,@TRANS_CD_DESC)"
            UpdateCommand="UPDATE CIS.CIS_TRANS SET TRANS_CD = @TRANS_CD, FUND_CD = @FUND_CD, BSA_CD = @BSA_CD, DP_TYPE = @DP_TYPE, TRANS_CD_DESC =@TRANS_CD_DESC WHERE ID = @ID">

        </asp:SqlDataSource>
4

2 回答 2

1

Oracle ADO.NET 库需要前缀:,而不是@在您传递给其引擎的每个参数中。

只需将参数的前缀从更改@:

于 2012-08-07T20:37:26.613 回答
0

您的 ID 字段是数字还是字符串。可能是 Cancel 有效而 DELETE 失败,因为在 Cancel 中,您在 ID 值周围使用单引号,而在 DELETE 中却没有。

于 2012-08-07T15:34:03.987 回答