在插入/更新时,SqlDataSource参数为空
本文关键字:SqlDataSource 参数 插入 更新 | 更新日期: 2023-09-27 18:04:15
我有一个SqlDataSource附加到用于插入/更新的FormView,它曾经完美地工作-但现在突然之间,没有一个参数被插入到行中(行仍然创建错误,但除了ID之外的所有字段都是空的)。我已经仔细检查,以确保所有正确的文本框的绑定到列名,他们是。
我只是想知道什么样的问题会导致这个,因为我被难住了。我已经附加到formview的DataBound方法只是为了确保表单不被反弹的回发,它不是。我还检查了插入方法和参数都是空的。
编辑:这是数据源标记:
<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>
在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);