iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi,
I have a WebGrid using a SQLDataSource. When trying to Update a Newly Inserted Row, it fails with " Object reference not set to an instance of an object."
There exists a SQL Insert Trigger, when it is not used, Updates on a Newly Inserted Row works.
Glenn has a working copy of the database an I have just provided him with the Trigger.
As a workaround, after refreshing the WebGrid, there is no problem even with the SQL Insert Trigger.
Why is this happening?
Is there a better solution?
Thanks,
Doug
Trigger:
CREATE TRIGGER tr_PARTS_DETAIL_Insert ON PARTS_DETAIL FOR INSERT AS IF @@rowcount < 1 RETURN BEGIN DECLARE @PartsDetialID INT DECLARE @PartsOrderNum INT DECLARE PartsDetailInserts CURSOR FAST_FORWARD FOR SELECT I.PARTS_DETAIL_ID , I.PARTS_ORDER_NUM FROM inserted I OPEN PartsDetailInserts FETCH NEXT FROM PartsDetailInserts INTO @PartsDetialID , @PartsOrderNum WHILE @@FETCH_STATUS = 0 BEGIN UPDATE PARTS SET PART_PRICE_TOTAL = dbo.fnParts_PartPriceTotal(@PartsOrderNum) WHERE [PARTS_ORDER#] = @PartsOrderNum FETCH NEXT FROM PartsDetailInserts INTO @PartsDetialID , @PartsOrderNum END CLOSE PartsDetailInserts DEALLOCATE PartsDetailInserts END RETURN
Code:
<%@ Page Language="C#" %> <%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <ISWebGrid:WebGrid ID="PartsDetail_WebGrid" runat="server" UseDefaultStyle="True" DataSourceID="PartsDetail_SQLDataSource" Height="250px" Width="100%" > <LayoutSettings AllowAddNew="Yes" AllowDelete="Yes" AllowEdit="Yes" AllowSorting="Yes" Hierarchical="false" > <ClientSideEvents /> </LayoutSettings> <RootTable DataKeyField="PARTS_DETAIL_ID" > <Columns> <ISWebGrid:WebGridColumn Name="PartsOrderNumber_WebGridColumn" DataMember="PARTS_ORDER_NUM" DataType="System.Int32" Width="100px" Visible="false" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="PartNumber_WebGridColumn" DataMember="PART_NUMBER" InputRequired="true" Width="130px" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="PartDescription_WebGridColumn" DataMember="PART_DESCRIPTION" InputRequired="true" Width="300px" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="PartQuantity_WebGridColumn" DataMember="QUANTITY" DataType="System.Int32" InputRequired="true" Width="70px" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="PartPrice_WebGridColumn" DataMember="PART_PRICE" DataType="System.Decimal" InputRequired="true" Width="80px" > </ISWebGrid:WebGridColumn> </Columns> </RootTable> </ISWebGrid:WebGrid> <asp:SqlDataSource ID="PartsDetail_SqlDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:NewCoAppSample %>' SelectCommand=" SELECT PD.PARTS_DETAIL_ID , PD.PARTS_ORDER_NUM , PD.QUANTITY , PD.PART_NUMBER , PD.PART_DESCRIPTION , PD.PART_PRICE FROM PARTS_DETAIL PD WHERE PD.PARTS_ORDER_NUM = 5 " DeleteCommand=" DELETE FROM PARTS_DETAIL WHERE PARTS_DETAIL_ID = @PARTS_DETAIL_ID " UpdateCommand=" UPDATE PARTS_DETAIL SET PART_NUMBER = @PART_NUMBER , PART_DESCRIPTION = @PART_DESCRIPTION , QUANTITY = @QUANTITY , PART_PRICE = @PART_PRICE WHERE PARTS_DETAIL_ID = @PARTS_DETAIL_ID " InsertCommand=" INSERT INTO PARTS_DETAIL ( PARTS_ORDER_NUM , PART_NUMBER , PART_DESCRIPTION , QUANTITY , PART_PRICE ) VALUES ( 5 , @PART_NUMBER , @PART_DESCRIPTION , @QUANTITY , @PART_PRICE ) " > <InsertParameters> <asp:Parameter Name="QUANTITY" Type="Decimal" /> <asp:Parameter Name="PART_NUMBER" Type="String" /> <asp:Parameter Name="PART_DESCRIPTION" Type="String" /> <asp:Parameter Name="PART_PRICE" Type="Decimal" /> </InsertParameters> <SelectParameters> </SelectParameters> <UpdateParameters> <asp:Parameter Name="QUANTITY" Type="Decimal" /> <asp:Parameter Name="PART_NUMBER" Type="String" /> <asp:Parameter Name="PART_DESCRIPTION" Type="String" /> <asp:Parameter Name="PART_PRICE" Type="Decimal" /> </UpdateParameters> </asp:SqlDataSource> </div> </form> </body> </html>
Error:
Server Error in '/NewCoServices' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] ISNet.WebUI.WebGrid.WebGridTable.IsKeyValueEqual(WebGridRow row, Object oKeyValues) +97
ISNet.WebUI.WebGrid.DataBinding. (DataView view, XmlNode xReq) +1396
ISNet.WebUI.WebGrid.DataBinding.(DataView dataSource, String request) +851
ISNet.WebUI.WebGrid.DataBinding.(DataView dataSource, String dataMember, String request) +776 ISNet.WebUI.WebGrid.DataBinding.DataBind(Object dataSource, String dataMember) +606 ISNet.WebUI.WebGrid.WebGrid.() +46 ISNet.WebUI.ISNetControl.ControlRequestHandler(Object sender, EventArgs e) +304 [Exception: Object reference not set to an instance of an object.] ISNet.WebUI.ISNetControl.ControlRequestHandler(Object sender, EventArgs e) +457 System.Web.UI.Control.OnPreRender(EventArgs e) +8682870 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Sorry for so many Replies.
It takes a while to figure out what characters this app does not like. Something non-printable.
Thank you for the sample, I have sucessfully replicate the issue.
However, I am still discussing the issue with our developer. I will inform you if I have any update or progress regarding this issue.
i have same problem while update operation. are there any solution for about this problem?
i fixed my problem. cause of the problem is empty DataKeyField of RootTable.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname