[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.3

How to get recordID back from SQL Server StoredProcedure

Asked by Delphiwizard in Delphi Programming, SQL Server 2005

Hi,

This question is about to getting the autoinc-value of the inserted record in my Delphi-application.

1. The first part is getting the StoredProcedure right:
Below you find the Stored procedure in SQL Server that should insert a new record into table AgendaRelaties and return the value of the AutoInc-field "ID"
When executing this code in SQL Server I get following errormessage:

Msg 1087, Level 15, State 2, Procedure AgendaRelatiesAdd, Line 15
Must declare the table variable "@TerugWaarde".

2. The second part is how to get to returned value into Delphi (in a multi-user environment)

Can anybody please correct the code below, so it will work correctly?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
1:
ALTER PROCEDURE [dbo].[AgendaRelatiesAdd] (
          @EigenBedrijfnr int,
          @Relatienr int,
          @Factureren bit,
          @TerugWaarde INT OUTPUT)
AS
BEGIN
    
	INSERT INTO dbo.AgendaRelaties (EIGENBEDRIJFNR, RELATIENR, FACTUREREN)
         OUTPUT ID INTO @TerugWaarde	VALUES (@EigenBedrijfnr, @Relatienr, @Factureren)
 
RETURN @@ERROR
END
 
2: 
// In Delphi DataModule
procedure TDM.AgendaRelatiesAdd(vRelatienr : Integer; vFactureren : Boolean);
begin
  Screen.Cursor := crHourglass;
  try
    with aspAgendaRelatiesAdd do
    begin
      Close;
      Parameters.ParamByName('@EIGENBEDRIJFNR').Value := vEigenBedrijfnr;
      Parameters.ParamByName('@Relatienr').Value      := vRelatienr;
      Parameters.ParamByName('@Factureren').Value     := vFactureren;
      Prepared := True;
      Open;
    end;
  finally
    CheckReturn(aspAgendaRelatiesAdd);
  end;
end;
 
procedure TDM.CheckReturn(SP: TADOStoredProc);
var TerugWaarde: Variant;
begin
  try
    TerugWaarde := SP.Parameters.ParamByName('@TerugWaarde').Value;
  except
    TerugWaarde := 0;
  end;
  if ((VarIsNull(TerugWaarde) = False) and (VarIsNumeric(TerugWaarde) = True)) then
  begin
    if (TerugWaarde = 0) then // Error occured
    begin
      // Log Error
    end else
    begin
      // New recordID
      NewRecordID := TerugWaarde;
    end;
  end;
  Screen.Cursor := crDefault;
end;
 
// Somewhere in my application:
DM.AgendaRelatiesAdd(QAgendaRelatiesSelecteren.FieldByName('Relatienr').AsInteger, QAgendaRelatiesSelecteren.FieldByName('Factureren').AsBoolean);
 
Related Solutions
Keywords: How to get recordID back from SQL Se…
 
Loading Advertisement...
 
[+][-]11/06/09 10:01 AM, ID: 25761388Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 10:15 AM, ID: 25761524Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/06/09 10:20 AM, ID: 25761575Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 10:23 AM, ID: 25761606Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 10:28 AM, ID: 25761664Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 10:34 AM, ID: 25761720Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 10:40 AM, ID: 25761775Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/06/09 10:42 AM, ID: 25761793Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 10:43 AM, ID: 25761803Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 10:49 AM, ID: 25761869Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 11:32 AM, ID: 25762309Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 11:36 AM, ID: 25762348Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 11:39 AM, ID: 25762375Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 11:41 AM, ID: 25762387Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 02:35 PM, ID: 25763687Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 02:39 PM, ID: 25763704Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 02:39 PM, ID: 25763705Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 02:42 PM, ID: 25763725Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Delphi Programming, SQL Server 2005
Sign Up Now!
Solution Provided By: 8080_Diver
Participating Experts: 2
Solution Grade: A
 
[+][-]11/06/09 03:19 PM, ID: 25763944Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 03:32 PM, ID: 25764014Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 05:51 PM, ID: 25764606Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 01:27 AM, ID: 25769916Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/09 07:01 AM, ID: 25776432Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 08:01 AM, ID: 25777052Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_EXPERT_20070906