开发者

SqlDataSource parameters are null on insert/update

I have an SqlDataSource attached to a FormView which is used for inserting/updating, which used to work perfectlly - but now all of a sudden, none of the parameters are inserted into the row (the row is still created with error, but all the fields except ID are null). I have double checked to make sure all correct textbox's are bound to the column name and they are.

I'm just wondering what sort of problems can cause this as I'm stumped. I've attached to the DataBound method of the formview just to make sure the form isn't being rebound on postback and it isn't. I've also checked out the Inserting method and the parameters are all null there.

EDIT: Here's the datasource markup:

<asp:SqlDataSource runat='server' ID='dsOrders' ConnectionString="<%$ ConnectionStrings:WebConnectionString %>"
                    SelectCommand="SELECT Orders.ID, Orders.Created, Orders.ReportingCat, Orders.OrderType, Orders.Customer, Orders.Reference, Orders.RequiredDate, Contacts.ContactName AS 'ContactName', ISNULL(Orders.Collection, 0) AS 'Collection', Orders.DirectToSite, Orders.OnSite, Orders.DelAdd1, Orders.DelAdd2, Orders.DelAdd3, Orders.DelTown, Orders.DelCounty, Orders.DelPostCode, Orders.Carriage, Orders.CarriageAmount, Orders.CarriageOverrideNote, Orders.SalesPerson, Orders.Offload, Orders.DelTimeBegin, Orders.DelTimeEnd, Orders.DeliveryInstruction, Orders.SpecialInstruction, Orders.AccountsNote, Orders.Status, SalesPeople.FirstName + ' ' + CASE WHEN SalesPeople.Surname IS NULL THEN '' ELSE SalesPeople.Surname END AS SalesName, ISNULL(Orders.ContactID, '') AS ContactID, Orders.OrderNumber, Orders.QuoteNumber, Orders.CustomerOrderLink, ISNULL(Orders.ProjectDetails, 0) AS 'ProjectDetails', Orders.SalesPersonContact, Orders.DeliveryCharge, Orders.SiteName, Orders.MainContractor, Orders.Address, Orders.Town, Orders.County, Orders.Postcode FROM Orders LEFT OUTER JOIN SalesPeople ON Orders.SalesPerson = SalesPeople.ID LEFT OUTER JOIN Contacts ON Orders.ContactID = Contacts.ContactID WHERE (Orders.ID = @Order ) OR ( @Order IS NULL)"
                    InsertCommand="INSERT INTO Orders(Customer, Collection, SalesPerson, Offload, Status, ContactID, OrderNumber, QuoteNumber, ProjectDetails, SalesPersonContact, DeliveryCharge) VALUES (@Customer, @Collection, @SalesPerson, @Offload, 1, @ContactID, @OrderNumber, @QuoteNumber, @ProjectDetails, @SalesPersonContact, @DeliveryCharge); SET @ReturnID = SCOPE_IDENTITY();"
                    OnInserted="dsOrders_Inserted" OnInserting="dsOrders_Inserting" UpdateCommand="UPDATE Orders SET Customer = @Customer, Collection = @Collection, SalesPerson = @SalesPerson, Offload = @Offload, ContactID = @ContactID, OrderNumber = @OrderNumber, QuoteNumber = @QuoteNumber, ProjectDetails = @ProjectDetails, SalesPersonContact = @SalesPersonContact, DeliveryCharge = @DeliveryCharge WHERE (ID = @ID)">
                    <UpdateParameters>
                        <asp:Parameter Name="Customer" Type="String" />
                        <asp:Parameter Name="Collection" Type="Boolean" />
                        <asp:Parameter Name="SalesPerson" Type="Int32" />
                        <asp:Parameter Name="Offload" Type="Boolean" />
                        <asp:Parameter Name="ContactID" Type="Int64" />
                        <asp:Parameter Name="OrderNumber" Type="Int64" />
                        <asp:Parameter Name="QuoteNumber" Type="String" />
                        <asp:Parameter Name="ProjectDetails" Type="Boolean" />
                        <asp:Parameter Name="SalesPersonContact" Type="Int64" />
                        <asp:Parameter Name="DeliveryCharge" Type="Int32" />
                        <asp:SessionParameter Name="ID" SessionField="OrderID" Type="Int64" />  
                    </UpdateParameters>
                    <InsertParameters>
 <asp:Parameter Name="Customer" Type="String" />
                        <asp:Parameter Name="Collection" Type="Boolean" />
                        <asp:Parameter Name="SalesPerson" Type="Int32" />
                        <asp:Parameter Name="Offload" Type="Boolean" />
                        <asp:Parameter Name="ContactID" Type="Int64" />
                        <asp:Parameter Name="OrderNu开发者_运维知识库mber" Type="Int64" />
                        <asp:Parameter Name="QuoteNumber" Type="String" />
                        <asp:Parameter Name="ProjectDetails" Type="Boolean" />
                        <asp:Parameter Name="SalesPersonContact" Type="Int64" />
                        <asp:Parameter Name="DeliveryCharge" Type="Int32" />
                        <asp:Parameter Name="ReturnID" Direction="Output" Type="Int64" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="null" Name="Order" SessionField="OrderID" />
                    </SelectParameters>
                </asp:SqlDataSource>


In your INSERT command I cannot see ID:

INSERT INTO Orders(Customer, Collection, SalesPerson, Offload, Status, ContactID,
OrderNumber, QuoteNumber, ProjectDetails, SalesPersonContact, DeliveryCharge) VALUES
(@Customer, @Collection, @SalesPerson, @Offload, 1, @ContactID, @OrderNumber, @QuoteNumber, 
@ProjectDetails, @SalesPersonContact, @DeliveryCharge);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜