Hi folks;
I'm having trouble retrieving the SCOPE_IDENTITY() with an SqlDataSource, it returns a number that has nothing to do with the real identity.
It was always returning 102 or 137 when the real identities were something in between 5 to 10
Here is my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString%>" DeleteCommand="DELETE FROM [POD] WHERE [PODID] = @.PODID" InsertCommand="INSERT INTO [POD] ([CustomerID], [Airbill], [Shipper], [Consignee], [POD], [Date], [Time], [Pieces], [Weight], [Comments]) VALUES (@.CustomerID, @.Airbill, @.Shipper, @.Consignee, @.POD, @.Date, @.Time, @.Pieces, @.Weight, @.Comments); SELECT SCOPE_IDENTITY() AS @.newID" SelectCommand="SELECT * FROM [POD] ORDER BY [POD]" UpdateCommand="UPDATE [POD] SET [CustomerID] = @.CustomerID, [Airbill] = @.Airbill, [Shipper] = @.Shipper, [Consignee] = @.Consignee, [POD] = @.POD, [Date] = @.Date, [Time] = @.Time, [Pieces] = @.Pieces, [Weight] = @.Weight, [Comments] = @.Comments WHERE [PODID] = @.PODID"> <DeleteParameters> <asp:Parameter Name="PODID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="CustomerID" Type="Int32" /> <asp:Parameter Name="Airbill" Type="String" /> <asp:Parameter Name="Shipper" Type="String" /> <asp:Parameter Name="Consignee" Type="String" /> <asp:Parameter Name="POD" Type="String" /> <asp:Parameter Name="Date" Type="DateTime" /> <asp:Parameter Name="Time" Type="DateTime" /> <asp:Parameter Name="Pieces" Type="Int32" /> <asp:Parameter Name="Weight" Type="Decimal" /> <asp:Parameter Name="Comments" Type="String" /> <asp:Parameter Name="PODID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="newID" Type="Int32" Direction="ReturnValue" /> <asp:Parameter Name="CustomerID" Type="Int32" /> <asp:Parameter Name="Airbill" Type="String" DefaultValue=" " /> <asp:Parameter Name="Shipper" Type="String" DefaultValue=" " /> <asp:Parameter Name="Consignee" Type="String" DefaultValue=" " /> <asp:Parameter Name="POD" Type="String" /> <asp:Parameter Name="Date" Type="DateTime" /> <asp:Parameter Name="Time" Type="DateTime" /> <asp:Parameter Name="Pieces" Type="Int32" DefaultValue="0" /> <asp:Parameter Name="Weight" Type="Decimal" DefaultValue="0" /> <asp:Parameter Name="Comments" Type="String" DefaultValue=" " /> </InsertParameters> </asp:SqlDataSource>
Protected Sub SqlDataSource1_Inserted(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)Handles SqlDataSource1.Inserted' ** get the id and redirect to details pageDim idAs Integer = e.Command.Parameters("@.newID").Value Response.Redirect("pod_details.aspx?id=" & ID)End SubDoes anybody know what am i doing wrong in here?
Change the direction of your "newID" Parameter from "ReturnValue" to "Output".
|||Hi;
Thanks for your help.
I also had to change fromSELECT SCOPE_IDENTITY() AS @.newID to SET @.newID =SCOPE_IDENTITY(), or else it returns a Null value.
No comments:
Post a Comment