我有一个SqlDataSource附加到FormView,用于插入/更新,它曾经完美地工作 - 但现在突然间,没有任何参数被插入到行中(该行仍然创建有错误,但除了ID之外的所有字段都是null。我已仔细检查以确保所有正确的文本框都绑定到列名称,并且它们是。
我只是想知道什么样的问题会导致这种情况,因为我很难过。我已经附加到formview的DataBound方法只是为了确保表单不会在回发时被反弹而事实并非如此。我还检查了Inserting方法,参数都是null。
编辑:这是数据源标记:
<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="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:Parameter Name="ReturnID" Direction="Output" Type="Int64" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter DefaultValue="null" Name="Order" SessionField="OrderID" />
</SelectParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
在INSERT
命令中,我看不到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);