Господа

Сложилась ситуация, когда в карте редактирования надо обеспечить пользователю возможность выбора некоторой сущности из другого набора данных.

В не визуальные компоненты окна - добавил необходимый набор данных, на форме разместил компонент LookupDataControl, для свойства DatasetLink - указал добавленный мной набор данных. Но при установке свойства DataFieldName - в журнал выбрасывается ошибка
"Невозможно установить имя поля "FieldName" для компонента "LookupDataControl""
В наборе данный ключевое поле, и первичное поле для отображения установлены.

В чём может быть причина ошибки?

С уважением
Егор

Нравится

4 комментария

Хотел использовать простой LookupControl, но при открытии окна выходит ошибка иного рода.

0x8000ffff - TSObjectLibrary.DBDataset: Ошибка открытия источника данных "ds_OrderGiftsList".

Оригинальное сообщение об ошибке: All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists

Егор, что представляет собой sq_OrderGiftsList, он содержит union-ы?
Если содержит, проверьте чтобы все union содержали одинаковое количество колонок с одинаковым набором свойств.

SELECT
	[ID],
	[Name],
	[LotID],
	[LotName],
	[IsJewel],
	[IsEvent],
	[GiftID],
	[GiftName],
	[AmountFrom],
	[GiftTypeID],
	[GiftDescription]
FROM
	(
    SELECT
  	  '{00000000-0000-0000-0000-000000000002}' AS [ID],
  	  NULL AS [Name],
  	  [tbl_LotInGift].[LotID] AS [LotID],
  	  [tbl_Lot].[Name] AS [LotName],
  	  [tbl_Lot].[IsJewel] AS [IsJewel],
  	  [tbl_Lot].[IsEvent] AS [IsEvent],
  	  [tbl_Gift].[ID] AS [GiftID],
  	  [tbl_Gift].[Name] AS [GiftName],
  	  [tbl_Gift].[AmountFrom] AS [AmountFrom],
  	  [tbl_Gift].[TypeID] AS [GiftTypeID],
  	  NULL AS [GiftDescription]
    FROM
	    [dbo].[tbl_Gift] AS [tbl_Gift]
    INNER JOIN
	    [dbo].[tbl_LotInGift] AS [tbl_LotInGift] ON [tbl_LotInGift].[GiftID] = [tbl_Gift].[ID]
    LEFT OUTER JOIN
	    [dbo].[tbl_Lot] AS [tbl_Lot] ON [tbl_Lot].[ID] = [tbl_LotInGift].[LotID]
    LEFT OUTER JOIN
	    [dbo].[tbl_SaleSource] AS [tbl_SaleSource] ON [tbl_SaleSource].[ChannelID] = [tbl_Gift].[ChannelID]
    WHERE([tbl_Gift].[TypeID] = :gtOrderNumber AND
	    :Date BETWEEN [tbl_Gift].[DateFrom] AND [tbl_Gift].[DateTo] AND
	    (([tbl_Gift].[SourceID] IS NULL AND
	    [tbl_Gift].[ChannelID] IS NULL) OR
	    ([tbl_Gift].[SourceID] IS NULL AND
	    [tbl_SaleSource].[ID] = :SourceID) OR
	    ([tbl_Gift].[SourceID] = :SourceID)) AND
	    [tbl_Lot].[StatusID] IN (:LotStatusIsOpen) AND
	    [tbl_Gift].[StateID] = :gfstActive AND
	    dbo.tsf_GetIsOrderNumberGiftAppllicable(:OrderNumber, tbl_Gift.OrderNumberPeriod,
      tbl_Gift.OrderNumberMaxCount, tbl_Gift.OrderNumberStartValue, tbl_Gift.OrderNumberCount)   = 1)
UNION ALL
SELECT
	N'{00000000-0000-0000-0000-000000000001}' AS [ID],
	NULL AS [Name],
	[tbl_LotInGift].[LotID] AS [LotID],
	[tbl_Lot].[Name] AS [LotName],
	[tbl_Lot].[IsJewel] AS [IsJewel],
	[tbl_Lot].[IsEvent] AS [IsEvent],
	[tbl_Gift].[ID] AS [GiftID],
	[tbl_Gift].[Name] AS [GiftName],
	[tbl_Gift].[AmountFrom] AS [AmountFrom],
	[tbl_Gift].[TypeID] AS [GiftTypeID],
	SetLot1Code + ';' + SetLot2Code AS [GiftDescription]
FROM
	[dbo].[tbl_Gift] AS [tbl_Gift]
INNER JOIN
	[dbo].[tbl_LotInGift] AS [tbl_LotInGift] ON [tbl_LotInGift].[GiftID] = [tbl_Gift].[ID]
LEFT OUTER JOIN
	[dbo].[tbl_Lot] AS [tbl_Lot] ON [tbl_Lot].[ID] = [tbl_LotInGift].[LotID]
LEFT OUTER JOIN
	[dbo].[tbl_SaleSource] AS [tbl_SaleSource] ON [tbl_SaleSource].[ChannelID] = [tbl_Gift].[ChannelID]
WHERE([tbl_Gift].[TypeID] = :gtLotSet AND
	:Date BETWEEN [tbl_Gift].[DateFrom] AND [tbl_Gift].[DateTo] AND
	(([tbl_Gift].[SourceID] IS NULL AND
	[tbl_Gift].[ChannelID] IS NULL) OR
	([tbl_Gift].[SourceID] IS NULL AND
	[tbl_SaleSource].[ID] = :SourceID) OR
	([tbl_Gift].[SourceID] = :SourceID)) AND
	[tbl_Gift].[StateID] = :gfstActive AND
	dbo.tsf_GetIsLotSetGiftAppllicable(:OrderID, tbl_Gift.ID) = 1 AND
	[tbl_Lot].[StatusID] IN (:LotStatusIsOpen))
UNION ALL
SELECT
	'{00000000-0000-0000-0000-000000000000}' AS [ID],
	NULL AS [Name],
	[tbl_LotInGift].[LotID] AS [LotID],
	[tbl_Lot].[Name] AS [LotName],
	[tbl_Lot].[IsJewel] AS [IsJewel],
	[tbl_Lot].[IsEvent] AS [IsEvent],
	[tbl_Gift].[ID] AS [GiftID],
	[tbl_Gift].[Name] AS [GiftName],
	[tbl_Gift].[AmountFrom] AS [AmountFrom],
	[tbl_Gift].[TypeID] AS [TypeID],
	NULL AS [GiftDescription]
FROM
	[dbo].[tbl_Gift] AS [tbl_Gift]
INNER JOIN
	[dbo].[tbl_LotInGift] AS [tbl_LotInGift] ON [tbl_LotInGift].[GiftID] = [tbl_Gift].[ID]
LEFT OUTER JOIN
	[dbo].[tbl_Lot] AS [tbl_Lot] ON [tbl_Lot].[ID] = [tbl_LotInGift].[LotID]
LEFT OUTER JOIN
	[dbo].[tbl_SaleSource] AS [tbl_SaleSource] ON [tbl_SaleSource].[ChannelID] = [tbl_Gift].[ChannelID]
WHERE([tbl_Gift].[TypeID] = :gtOrderAmount AND
	:Date BETWEEN [tbl_Gift].[DateFrom] AND [tbl_Gift].[DateTo] AND
	(([tbl_Gift].[SourceID] IS NULL AND
	[tbl_Gift].[ChannelID] IS NULL) OR
	([tbl_Gift].[SourceID] IS NULL AND
	[tbl_SaleSource].[ID] = :SourceID) OR
	([tbl_Gift].[SourceID] = :SourceID)) AND
	[tbl_Lot].[StatusID] IN (:LotStatusIsOpen) AND
	[tbl_Gift].[StateID] = :gfstActive AND
 
	(SELECT
		SUM([tbl_Partable].[Amount]) AS [Amount]
	FROM
		[dbo].[tbl_Orders] AS [tbl_Orders]
	LEFT OUTER JOIN
		[dbo].[tbl_Partable] AS [tbl_Partable] ON [tbl_Partable].[OrdersID] = [tbl_Orders].[ID]
	WHERE([tbl_Orders].[ID] = :OrderID AND
		[tbl_Partable].[default] = :TRUE AND
		[tbl_Partable].[IsGift] = :False)) BETWEEN [tbl_Gift].[AmountFrom] AND [tbl_Gift].[AmountTo])
UNION ALL
SELECT
	'{00000000-0000-0000-0000-000000000004}' AS [ID],
	NULL AS [Name],
	[tbl_LotInGift].[LotID] AS [LotID],
	[tbl_Lot].[Name] AS [LotName],
	[tbl_Lot].[IsJewel] AS [IsJewel],
	[tbl_Lot].[IsEvent] AS [IsEvent],
	[tbl_Gift].[ID] AS [GiftID],
	[tbl_Gift].[Name] AS [GiftName],
	[tbl_Gift].[AmountFrom] AS [AmountFrom],
	[tbl_Gift].[TypeID] AS [TypeID],
	NULL AS [GiftDescription]
FROM
	[dbo].[tbl_Gift] AS [tbl_Gift]
INNER JOIN
	[dbo].[tbl_LotInGift] AS [tbl_LotInGift] ON [tbl_LotInGift].[GiftID] = [tbl_Gift].[ID]
LEFT OUTER JOIN
	[dbo].[tbl_Lot] AS [tbl_Lot] ON [tbl_Lot].[ID] = [tbl_LotInGift].[LotID]
LEFT OUTER JOIN
	[dbo].[tbl_SaleSource] AS [tbl_SaleSource] ON [tbl_SaleSource].[ChannelID] = [tbl_Gift].[ChannelID]
WHERE([tbl_Gift].[TypeID] = :gtClientLoyalty AND
	:Date BETWEEN [tbl_Gift].[DateFrom] AND [tbl_Gift].[DateTo] AND
	(([tbl_Gift].[SourceID] IS NULL AND
	[tbl_Gift].[ChannelID] IS NULL) OR
	([tbl_Gift].[SourceID] IS NULL AND
	[tbl_SaleSource].[ID] = :SourceID) OR
	([tbl_Gift].[SourceID] = :SourceID) OR
	[tbl_Lot].[StatusID] IN (:LotStatusIsOpen) OR
	[tbl_Gift].[StateID] = :gfstActive) AND
	[tbl_Gift].[LoyaltyID] = :LoyaltyID)
UNION ALL
SELECT
	[tbl_Partable].[LotsID] AS [ID],
	[ReasonLot].[Name] AS [Name],
	[tbl_LotInGift].[LotID] AS [LotID],
	[tbl_Lot].[Name] AS [LotName],
	[tbl_Lot].[IsJewel] AS [IsJewel],
	[tbl_Lot].[IsEvent] AS [IsEvent],
	[tbl_Gift].[ID] AS [GiftID],
	[tbl_Gift].[Name] AS [GiftName],
	[tbl_Gift].[AmountFrom] AS [AmountFrom],
	[tbl_Gift].[TypeID] AS [TypeID],
	cast([tbl_Partable].[LotsID] as nvarchar(40)) AS [GiftDescription]
FROM
	[dbo].[tbl_Orders] AS [tbl_Orders]
LEFT OUTER JOIN
	[dbo].[tbl_Partable] AS [tbl_Partable] ON [tbl_Partable].[OrdersID] = [tbl_Orders].[ID]
LEFT OUTER JOIN
	[dbo].[tbl_Gift] AS [tbl_Gift] ON [tbl_Gift].[LotID] = [tbl_Partable].[LotsID]
LEFT OUTER JOIN
	[dbo].[tbl_LotInGift] AS [tbl_LotInGift] ON [tbl_LotInGift].[GiftID] = [tbl_Gift].[ID]
LEFT OUTER JOIN
	[dbo].[tbl_Lot] AS [tbl_Lot] ON [tbl_Lot].[ID] = [tbl_LotInGift].[LotID]
LEFT OUTER JOIN
	[dbo].[tbl_SaleSource] AS [tbl_SaleSource] ON [tbl_SaleSource].[ID] = [tbl_Orders].[SourceID]
LEFT OUTER JOIN
	[dbo].[tbl_Lot] AS [ReasonLot] ON [ReasonLot].[ID] = [tbl_Partable].[LotsID]
WHERE([tbl_Gift].[TypeID] = :gtOrderQuantity AND
	:Date BETWEEN [tbl_Gift].[DateFrom] AND [tbl_Gift].[DateTo] AND
	(([tbl_Gift].[SourceID] IS NULL AND
	[tbl_Gift].[ChannelID] IS NULL) OR
	([tbl_Gift].[SourceID] IS NULL AND
	[tbl_Gift].[ChannelID] = [tbl_SaleSource].[ChannelID]) OR
	([tbl_Gift].[SourceID] = :SourceID)) AND
	[tbl_Gift].[StateID] = :gfstActive AND
	[tbl_Orders].[ID] = :OrderID AND
	[tbl_Partable].[default] = :TRUE AND
	[tbl_Partable].[IsGift] = :False AND
	[tbl_Lot].[StatusID] IN (:LotStatusIsOpen) AND
	0 = 0) 
GROUP BY
        [tbl_Gift].[ID],
        [tbl_Gift].[Name],
       	[ReasonLot].[Name],
        [tbl_LotInGift].[ID],        
	[tbl_Partable].[LotsID],
	[tbl_LotInGift].[LotID],
	[tbl_Lot].[Name],
	[tbl_Lot].[IsJewel],
	[tbl_Lot].[IsEvent],
	[tbl_Gift].[QuantityFrom],
	[tbl_Gift].[QuantityTo],
	[tbl_Gift].[TypeID],
	[tbl_Gift].[AmountFrom]
 
HAVING COUNT([tbl_Partable].[ID]) BETWEEN [tbl_Gift].[QuantityFrom]   AND [tbl_Gift].[QuantityTo]
 
) AS [U] ORDER BY [ID] --	)) AS [U]

Вот такая страшная штука.
Этот sq был создан давно, и каким то образом функционирует в системе.
Но как только я захотел получить набор данных на его основании, он выдал ошибку.

Yegor, первое что бросается в глаза - заголовок 10-й колонки в первых 3-х подзапросах (union) GiftTypeID, а в последующих TypeID, что некорректно.
Вам нужно изменить заголовки и свойства колонок в запросе таким образом, чтобы они были одинаковы во всех union-х.

Показать все комментарии