473,799 Members | 2,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return value

Hi,

Is it possible to make a stored procedure or function to generate a return
value?

I have a stored procedure which inserts a new row in a table. I would like
that proceudre to return the ID (autogenerated field) of the row after it
has
inserted it.

Gunnar
Nov 12 '05 #1
3 2216
DFS

"Gunnar Liknes" <g_liknes.Tabor tunderscores@g_ lobal-satcom.com> wrote in
message news:40******** @news.broadpark .no...
Hi,

Is it possible to make a stored procedure or function to generate a return
value?

I have a stored procedure which inserts a new row in a table. I would like
that proceudre to return the ID (autogenerated field) of the row after it
has
inserted it.

Gunnar

Gunnar,

Try this:

Public Function (newRecordID) as Long

'place your stored proc code to add new row here

'return latest ID
newRecordID = DMax("ID","Tabl e")

End Function
Note: you need to add some error trapping in the function to ensure your
Insert completes successfully, or the newRecordID might not be the ID of the
newest record.



Nov 12 '05 #2
"DFS" wrote
"Gunnar Liknes" wrote in
Is it possible to make a stored procedure or function to generate a return value?

I have a stored procedure which inserts a new row in a table. I would like that proceudre to return the ID (autogenerated field) of the row after it has
inserted it.

Try this:

Public Function (newRecordID) as Long

'place your stored proc code to add new row here

'return latest ID
newRecordID = DMax("ID","Tabl e")

End Function
Note: you need to add some error trapping in the function to ensure your
Insert completes successfully, or the newRecordID might not be the ID of the newest record.


Thank you:-) But Where do I put in this code? If I try to enter it in SQL
view
I get an error message saying "SQL Batch has to begin with ALTER or
CREATE"...

Gunnar
Nov 12 '05 #3
DFS

"Gunnar Liknes" <g_liknes.Tabor tunderscores@g_ lobal-satcom.com> wrote in
message news:40******** @news.broadpark .no...
"DFS" wrote
"Gunnar Liknes" wrote in

Is it possible to make a stored procedure or function to generate a return value?

I have a stored procedure which inserts a new row in a table. I would like that proceudre to return the ID (autogenerated field) of the row after it has
inserted it.

Try this:

Public Function (newRecordID) as Long

'place your stored proc code to add new row here

'return latest ID
newRecordID = DMax("ID","Tabl e")

End Function
Note: you need to add some error trapping in the function to ensure your
Insert completes successfully, or the newRecordID might not be the ID of

the
newest record.


Thank you:-) But Where do I put in this code? If I try to enter it in SQL
view
I get an error message saying "SQL Batch has to begin with ALTER or
CREATE"...

Add this Function to a Module. Your stored proc code (that adds a new row)
also goes inside this function. Then the new Function is called in place of
your stored procedure.

Something like:

Public Function (newRecordID) as Long
'this function adds a new record and returns the ID

'code to add new row here
db.Execute("INS ERT INTO Table (Field1, Field2) VALUES ('Gunnar','test ');")

'return latest ID
newRecordID = DMax("ID","Tabl e")

End Function

Public Sub testNewRecordID ()
msgbox "Record added. ID = " & newRecordID()
End Sub

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3048
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart) pointer, or reference Date: 27 Aug 2005 15:13:23 -0400 From: Neal Coombes <nealc@trdlnk.com> Organization: Aioe.org NNTP Server To: (Usenet) Newsgroups: comp.lang.c++.moderated
16
2001
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't see how the return value comes to play here. Ex
15
2810
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
12
4133
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport) {
3
2367
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They do work pretty well, except for the change I made to get the return value. For example, I have the following: ********************************************************************** Public Overloads Function RunProcedure( _ ByVal storedProcName...
12
3799
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. 1. The Deserialization goes like: #Region " Load "
20
3615
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this exit(n)) statement provide both function call and return features of the C programming language? /* headers omitted */ int main (void)
6
1894
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document that describes this. Here's the setup. We have a COM server, written in Python. For completeness, here is the script: ----- testserver.py ----- import pythoncom
7
10328
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer) As Boolean Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean If lvServers.InvokeRequired = True Then lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),...
6
2412
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class Card { // instance variables //suits private int suit; private int spades;
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.