IDENTITY columns

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Werner52
Posts: 4
Joined: Wed 11 Nov 2015 03:48

IDENTITY columns

Post by Werner52 » Thu 12 Nov 2015 09:50

Problem with IDENTITY columns. After insert into a table, the Field is not automatically populated with the IDENTITY value.This is bad, because I need the value in a detailed dataset.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: IDENTITY columns

Post by AlexP » Thu 12 Nov 2015 13:17

Hello,

In order to automatically fill in IDENTITY after calling the Post method, you should set the QueryIdentity and ReturnParams properties of DataSet to True.

Werner52
Posts: 4
Joined: Wed 11 Nov 2015 03:48

Re: IDENTITY columns

Post by Werner52 » Thu 12 Nov 2015 13:52

Hallo AlexP

Sorry, does not have any success here my parameters in TMSQuery


object ARTIKEL: TMSQuery
SQLInsert.Strings = (
'INSERT INTO ARTIKEL'

' (CDATE, CUSER_ID, ARTIKELNR, SUCHBEGRIFF, STATUS, ARTIKELART, ' +
'MEINHEIT, STEUER_ID, WARENGRUPPEN_ID, KALKEKPREIS, DATEKALKPREIS' +
', EKPFESTLEGUNG, LISTENPREIS, PACKEINH, HERSTELLER_ID, GEWICHT, ' +
'EANNUMMER, SERIENNUMMER)'
'VALUES'

' (:CDATE, :CUSER_ID, :ARTIKELNR, :SUCHBEGRIFF, :STATUS, :ARTIKE' +
'LART, :MEINHEIT, :STEUER_ID, :WARENGRUPPEN_ID, :KALKEKPREIS, :DA' +
'TEKALKPREIS, :EKPFESTLEGUNG, :LISTENPREIS, :PACKEINH, :HERSTELLE' +
'R_ID, :GEWICHT, :EANNUMMER, :SERIENNUMMER)'
'SET :ARTIKEL_ID = SCOPE_IDENTITY()')
SQLDelete.Strings = (
'DELETE FROM ARTIKEL'
'WHERE'
' ARTIKEL_ID = :Old_ARTIKEL_ID')
SQLUpdate.Strings = (
'UPDATE ARTIKEL'
'SET'

' CDATE = :CDATE, CUSER_ID = :CUSER_ID, ARTIKELNR = :ARTIKELNR, ' +
'SUCHBEGRIFF = :SUCHBEGRIFF, STATUS = :STATUS, ARTIKELART = :ARTI' +
'KELART, MEINHEIT = :MEINHEIT, STEUER_ID = :STEUER_ID, WARENGRUPP' +
'EN_ID = :WARENGRUPPEN_ID, KALKEKPREIS = :KALKEKPREIS, DATEKALKPR' +
'EIS = :DATEKALKPREIS, EKPFESTLEGUNG = :EKPFESTLEGUNG, LISTENPREI' +
'S = :LISTENPREIS, PACKEINH = :PACKEINH, HERSTELLER_ID = :HERSTEL' +
'LER_ID, GEWICHT = :GEWICHT, EANNUMMER = :EANNUMMER, SERIENNUMMER' +
' = :SERIENNUMMER'
'WHERE'
' ARTIKEL_ID = :Old_ARTIKEL_ID')
SQLRefresh.Strings = (

'SELECT CDATE, CUSER_ID, ARTIKELNR, SUCHBEGRIFF, STATUS, ARTIKELA' +
'RT, MEINHEIT, STEUER_ID, WARENGRUPPEN_ID, KALKEKPREIS, DATEKALKP' +
'REIS, EKPFESTLEGUNG, LISTENPREIS, PACKEINH, HERSTELLER_ID, GEWIC' +
'HT, EANNUMMER, SERIENNUMMER FROM ARTIKEL'
'WHERE'
' ARTIKEL_ID = :ARTIKEL_ID')
SQLLock.Strings = (
'SELECT * FROM ARTIKEL'
'WITH (UPDLOCK, ROWLOCK, HOLDLOCK)'
'WHERE'
' ARTIKEL_ID = :Old_ARTIKEL_ID')
SQLRecCount.Strings = (
'SET :PCOUNT = (SELECT COUNT(*) FROM ARTIKEL'
')')
Connection = DM.MASTER
SQL.Strings = (
'Select * from ARTIKEL')
Debug = True
Options.CheckRowVersion = True
Options.ReturnParams = True
Left = 264
Top = 96
object ARTIKELARTIKEL_ID: TIntegerField
AutoGenerateValue = arAutoInc
FieldName = 'ARTIKEL_ID'
ReadOnly = True
end
object ARTIKELCUSER_ID: TIntegerField
FieldName = 'CUSER_ID'
end
object ARTIKELARTIKELNR: TWideStringField
FieldName = 'ARTIKELNR'
Size = 40
end
object ARTIKELSUCHBEGRIFF: TWideStringField
FieldName = 'SUCHBEGRIFF'
Size = 80
end
object ARTIKELSTATUS: TWideStringField
FieldName = 'STATUS'
FixedChar = True
Size = 1
end
object ARTIKELARTIKELART: TStringField
FieldName = 'ARTIKELART'
FixedChar = True
Size = 1
end
object ARTIKELMEINHEIT: TWideStringField
FieldName = 'MEINHEIT'
Size = 5
end
object ARTIKELSTEUER_ID: TIntegerField
FieldName = 'STEUER_ID'
end
object ARTIKELWARENGRUPPEN_ID: TIntegerField
FieldName = 'WARENGRUPPEN_ID'
end
object ARTIKELKALKEKPREIS: TCurrencyField
FieldName = 'KALKEKPREIS'
end
object ARTIKELEKPFESTLEGUNG: TStringField
FieldName = 'EKPFESTLEGUNG'
FixedChar = True
Size = 1
end
object ARTIKELLISTENPREIS: TCurrencyField
FieldName = 'LISTENPREIS'
end
object ARTIKELPACKEINH: TFloatField
FieldName = 'PACKEINH'
Precision = 4
end
object ARTIKELHERSTELLER_ID: TIntegerField
FieldName = 'HERSTELLER_ID'
end
object ARTIKELGEWICHT: TFloatField
FieldName = 'GEWICHT'
Precision = 6
end
object ARTIKELEANNUMMER: TWideStringField
FieldName = 'EANNUMMER'
FixedChar = True
Size = 15
end
object ARTIKELSERIENNUMMER: TBooleanField
FieldName = 'SERIENNUMMER'
end
object ARTIKELWARENGRUPPE: TStringField
FieldKind = fkLookup
FieldName = 'WARENGRUPPE'
LookupDataSet = DM.WARENGRUPPEN
LookupKeyFields = 'WARENGRUPPEN_ID'
LookupResultField = 'WARENGRUPPE'
KeyFields = 'WARENGRUPPEN_ID'
Size = 32
Lookup = True
end
object ARTIKELWARENGRUPPEBEZ: TStringField
FieldKind = fkLookup
FieldName = 'WARENGRUPPEBEZ'
LookupDataSet = DM.WARENGRUPPEN
LookupKeyFields = 'WARENGRUPPEN_ID'
LookupResultField = 'BEZEICHNUNG'
KeyFields = 'WARENGRUPPEN_ID'
Size = 255
Lookup = True
end
object ARTIKELHERSTELLER: TStringField
FieldKind = fkLookup
FieldName = 'HERSTELLER'
LookupDataSet = HERSTELLER
LookupKeyFields = 'HERSTELLER_ID'
LookupResultField = 'HERSTELLER'
KeyFields = 'HERSTELLER_ID'
Size = 80
Lookup = True
end
object ARTIKELCDATE: TDateTimeField
FieldName = 'CDATE'
end
object ARTIKELDATEKALKPREIS: TDateTimeField
FieldName = 'DATEKALKPREIS'
end
end

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: IDENTITY columns

Post by AlexP » Mon 16 Nov 2015 05:42

Please provide the table creating script.

Werner52
Posts: 4
Joined: Wed 11 Nov 2015 03:48

Re: IDENTITY columns

Post by Werner52 » Sat 21 Nov 2015 15:18

CREATE TABLE [dbo].[ARTIKEL](
[ARTIKEL_ID] [int] IDENTITY(1,1) NOT NULL,
[CDATE] [datetime2](7) NULL,
[CUSER_ID] [int] NULL,
[ARTIKELNR] [nvarchar](40) NOT NULL,
[SUCHBEGRIFF] [nvarchar](80) NULL,
[STATUS] [nchar](1) NULL,
[ARTIKELART] [char](1) NULL,
[MEINHEIT] [nvarchar](5) NULL,
[STEUER_ID] [int] NULL,
[WARENGRUPPEN_ID] [int] NULL,
[KALKEKPREIS] [money] NULL,
[DATELISTENPREIS] [datetime2](7) NULL,
[DATEKALKPREIS] [datetime2](7) NULL,
[USERKALKEKPREIS] [int] NULL,
[USERLISTENPREIS] [int] NULL,
[EKPFESTLEGUNG] [char](1) NULL,
[LISTENPREIS] [money] NULL,
[PACKEINH] [numeric](4, 0) NULL,
[HERSTELLER_ID] [int] NULL,
[GEWICHT] [numeric](6, 0) NULL,
[EANNUMMER] [nchar](15) NULL,
[SERIENNUMMER] [bit] NULL,
[STUECKLISTENARTIKEL] [bit] NULL,
[WARTUNGERFORDERLICH] [bit] NULL,
[LAGERARTIKEL] [bit] NULL,
CONSTRAINT [PK_ARTIKEL_1] PRIMARY KEY CLUSTERED
(
[ARTIKEL_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

azyk
Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: IDENTITY columns

Post by azyk » Mon 23 Nov 2015 09:45

To solve the described issue, in addition to the solution suggested by AlexP, set the AutoGenerateValue property to arNone for the IDENTITY field.

Werner52
Posts: 4
Joined: Wed 11 Nov 2015 03:48

Re: IDENTITY columns

Post by Werner52 » Tue 24 Nov 2015 18:51

Thank you for your trouble, I have taken a different path. I do not use identity columns. I have tried many things. That takes me too long.

Post Reply