473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2191
DFS

"Gunnar Liknes" <g_liknes.Tabortunderscores@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","Table")

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","Table")

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.Tabortunderscores@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","Table")

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("INSERT INTO Table (Field1, Field2) VALUES ('Gunnar','test');")

'return latest ID
newRecordID = DMax("ID","Table")

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
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)...
16
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...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
12
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
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...
12
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. ...
20
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...
6
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...
7
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.