更新gridview行错误

时间:2013-08-15 07:32:51

标签: asp.net sql gridview updatecommand

<asp:SqlDataSource ID="charges_gv_datasource" runat="server" ConnectionString="edited"
ProviderName="System.Data.OracleClient" SelectCommand="WITH relevant_ids AS (SELECT ir.result_id AS relevant_result_id FROM inspection_result_tbl ir) SELECT ir.charge_id, LISTAGG(ir.result_id, ', ') WITHIN GROUP (ORDER BY ir.charge_id) AS result_ids, ch.charge_progress, ch.claim_verification, ch.hours_allowed, ch.sap_notification, ch.total_checked, ch.charge FROM inspection_result_tbl ir LEFT JOIN relevant_ids ON ir.result_id=relevant_ids.relevant_result_id LEFT JOIN charges_tbl ch ON ir.charge_id=ch.charge_id WHERE ir.charge_id IS NOT NULL AND ir.result_id=relevant_ids.relevant_result_id GROUP BY ir.charge_id, ch.charge_progress, ch.claim_verification, ch.hours_allowed, ch.sap_notification, ch.total_checked, ch.charge" 
UpdateCommand="UPDATE [charges_tbl] SET [CLAIM_VERIFICATION] = :claim_verification, [CHARGE_PROGRESS] = :charge_progress, [SAP_NOTIFICATION] = :sap_notification WHERE [CHARGE_ID] = :charge_id">

                             </asp:SqlDataSource>

                            <asp:GridView ID="charges_gv" runat="server" AutoGenerateEditButton="true" DataSourceID="charges_gv_datasource" DataKeyNames="charge_id"
                            AutoGenerateColumns="false" Width="805px">
                            <Columns>
                                <asp:TemplateField HeaderText="Charge ID" SortExpression="charge_id">
                                    <EditItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("charge_id") %>'></asp:Label>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("charge_id") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <%--<asp:BoundField DataField="charge_id" HeaderText="Charge ID" ItemStyle-HorizontalAlign="Center" />--%>
                                <%--<asp:BoundField DataField="result_ids" HeaderText="Result ID" ItemStyle-HorizontalAlign="Center" />--%>
                                <asp:TemplateField HeaderText="Result ID" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Label ID="resultid" runat="server" Text='<%# Bind("result_ids")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Total Checked" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Label ID="totalCheckedCT" runat="server" Text='<%# Eval("total_checked")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Hours Allowed" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Label ID="hoursAllowedCT" runat="server" Text='<%# Eval("hours_allowed")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Charge" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Label ID="chargeCT" runat="server"  Text='<%# Eval("charge")%>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="claim_verification" HeaderText="Claim Verification" ItemStyle-HorizontalAlign="Center"  />
                                <asp:BoundField DataField="charge_progress" HeaderText="Charge Progress" ItemStyle-HorizontalAlign="Center" />
                                <asp:BoundField DataField="sap_notification" HeaderText="SAP Notification" ItemStyle-HorizontalAlign="Center" />
                            </Columns>
                        </asp:GridView>

我有一个数据源和一个网格视图,我正在尝试在gridview行上启用编辑。一切都很完美,所以我可以点击编辑,字段更改为文本框,取消和更新按钮apear和工作但如果我更改值并单击更新按钮我得到错误:

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

任何想法为什么?我检查了updatecommand中的所有拼写,这一切都是正确的。请帮帮我。

堆栈追踪:

[OracleException (0x80131938): ORA-01036: illegal variable name/number
]
   System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc) +488568
   System.Data.OracleClient.OracleParameterBinding.Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, Boolean& mustRelease, SafeHandle& handleToBind) +1297
   System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals) +1204
   System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor) +656
   System.Data.OracleClient.OracleCommand.ExecuteNonQuery() +158
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +2790646
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +4065616
   System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1350
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +626
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +110
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

1 个答案:

答案 0 :(得分:1)

为什么会出现这种情况有很多原因。有时因为我们不使用Oracle工具,有时因为gridview标记不正确。

因为您不需要更新Column charge_id的值,所以除非您在DataKeyNames SqlDataSource属性中指定它,否则不能使用BoundField。

如果未在DataKeyNames中指定BoundField,则生成一个绑定变量,如果在update语句中未使用该变量将导致ORA-01036。要避免错误,请在DataKeyNames属性中指定此字段或将其更改为TemplateField并使用Eval.so我认为有两种可能的情况:

1。)将SqlDataSource的DataKeyNames属性设置为charge_id

<asp:SqlDataSource ID="charges_gv_datasource" runat="server" ConnectionString="edited"
 ProviderName="System.Data.OracleClient" 
 DataKeyNames="charge_id"
 SelectCommand="WITH relevant_ids AS (SELECT ir.result_id AS relevant_result_id 
 FROM inspection_result_tbl ir) SELECT ir.charge_id, ....." 
 UpdateCommand="UPDATE [charges_tbl] SET [CLAIM_VERIFICATION] = :claim_verification,...">

2。)如果选项1不适合:

看到你的标记,肯定你已经有了<EditItemTemplate>,因为许多<asp:TemplateField>项目没有显示相同的内容。

确保您将charge_id列放在<asp:TemplateField>中。使用<asp:Lable>即使在编辑模式下也不会更改。

<asp:TemplateField HeaderText="charge_id" SortExpression="charge_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("charge_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("charge_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

看到稍后提供的堆栈跟踪,: 最好将VS开发人员工具(ODT)用于VS和ODP.NET,因为它们可以更好地与.NET和Oracle集成。

ODP.NET使用Oracle.DataAccess.Client命名空间。 System.Data.OracleClient属于Oracle的MS提供程序。 web.config中的连接字符串需要使用Oracle.DataAccess.Client,如下所示:

<connectionStrings>
<add name="ConnectionString1" 
 connectionString="Data Source=192.168.1.104/orcl;Persist Security Info=True;User    
 ID=system;Password=xxxxxx;"
 providerName="Oracle.DataAccess.Client" />
</connectionStrings>

查看完整帖子以供参考:https://forums.oracle.com/message/2368331?#2366331http://forums.oracle.com/forums/thread.jspa?threadID=62196