更新/插入信息时出错

本文关键字:出错 信息 插入 更新 | 更新日期: 2024-11-06 00:53:45

我在下面收到此错误:

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>

更新/插入信息时出错

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

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

您的 ID 字段是数字还是字符串。 可能是"取消"有效,而"删除"失败,因为在"取消"中,您在 ID 值周围使用单引号,而在"删除"中则不然。