我收到以下错误:
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>
答案 0 :(得分:1)
Oracle ADO.NET库在传递给引擎的每个参数中都需要前缀:
而不是@
。
只需将参数的前缀从@
更改为:
答案 1 :(得分:0)
您的ID字段是数字还是字符串。可能是取消工作而DELETE失败,因为在取消中,您在ID值周围使用单引号,而在DELETE中则不是。