Returning server side newid() uniqueidentifier after insert
Posted: Tue 21 Jun 2011 12:26
I have the following table in SQL Server:
In my Delphi application I have the following setup:
DataSource -> ClientDataSet -> DataSetProvider -> TMSQuery
The TMSQuery.SQL.Text is:
I have set the Parameter CategoryID to be of type GUID.
All fields have been added to both the TMSQuery component AND the ClientDataSet. The parameter has also been added to the ClientDataSet.
When the system inserts a new record, I do the following (the CategoryID parameter value is NIL as it will be created on the server):
How can I get the CategoryIDas it is created on the server (using newid())? Are there any settings I can set on the TMSQuery (or DataProvider) to get this value back?
Best Regards,
Tom Reiertsen
Code: Select all
CREATE TABLE [dbo].[Category](
[CategoryID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ParentCategoryID] [uniqueidentifier] NULL,
[Name] [nvarchar](255) NOT NULL,
[Description] [nvarchar](1024) NULL,
CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED
DataSource -> ClientDataSet -> DataSetProvider -> TMSQuery
The TMSQuery.SQL.Text is:
Code: Select all
TMSQuery.SQL.Text := 'SELECT * FROM [Category] WHERE [CategoryID]=:CategoryID;';
All fields have been added to both the TMSQuery component AND the ClientDataSet. The parameter has also been added to the ClientDataSet.
When the system inserts a new record, I do the following (the CategoryID parameter value is NIL as it will be created on the server):
Code: Select all
ClientDataSet.Open;
ClientDataSet.Append;
ClientDataSetName.AsString := 'Test';
ClientDataSet.ApplyUpdates(0);
Best Regards,
Tom Reiertsen