473,698 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve Identity Field Value from a stored procedure into a form

8 New Member
OK first time poster, so hello everyone in advance. Right i'm sure this is a simple problem to solve, but I'm just getting the hang of SQL 2000. What I've got is a form where I input the values and then through a procedure these values are inserted into a table. That's fine. However I now need to open a subform which is linked by the ID field created through the first procedure. How do I retrieve that value back into the form??


The procedure code is

CREATE PROCEDURE InsertFamilyDet ails

@CarerID varChar(6),
@FamilyName varChar(30),
@Address1 varChar(30),
@Address2 varChar(30),
@Address3 varChar(30),
@PostCodeMain varChar(4),
@PostCodeSub varChar(30),
@PhoneNo varChar(16),
@LocalTransport varChar(200),
@Leisure varChar(200),
@School varChar(200),
@Rules varChar(250),
@Result int OUTPUT

AS

DECLARE @FamilyID int;

BEGIN TRANSACTION

-- Insert New Family

SELECT @FamilyID=@@Ide ntity

INSERT INTO tblWfsFamilyDet ails

(intCarerID,txt FamilyName,txtA ddress1,txtAddr ess2,txtAddress 3,txtPostCodeMa in,txtPostCodeS ub,txtPhoneNo,m emoLocalTranspo rt, memoLeisure, memoSchool,memo Rules)

VALUES

(@CarerID,@Fami lyName,@Address 1,@Address2,@Ad dress3,@PostCod eMain,@PostCode Sub,@PhoneNo,@L ocalTransport,@ Leisure,@School ,@Rules)



IF @RESULT<1

BEGIN

ROLLBACK TRANSACTION;

RETURN -1

END

SET @RESULT=1

COMMIT TRANSACTION
GO

Whereas, the VB Code is

Private Sub cmdInsert_Click ()
Set cmd = New ADODB.Command
cmd.ActiveConne ction = con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "insertFamilyDe tails"

' FieldNames Assigned to FormControls

cmd.Parameters. Append cmd.CreateParam eter("CarerID", adInteger, adParamInput, 6, txtCarerID)
cmd.Parameters. Append cmd.CreateParam eter("FamilyNam e", adVarChar, adParamInput, 30, txtFamilyName)
cmd.Parameters. Append cmd.CreateParam eter("Address1" , adVarChar, adParamInput, 30, txtAddress1)
cmd.Parameters. Append cmd.CreateParam eter("Address2" , adVarChar, adParamInput, 30, txtAddress2)
cmd.Parameters. Append cmd.CreateParam eter("Address3" , adVarChar, adParamInput, 30, txtAddress3)
cmd.Parameters. Append cmd.CreateParam eter("PostCodeM ain", adVarChar, adParamInput, 4, txtPostCodeMain )
cmd.Parameters. Append cmd.CreateParam eter("PostCodeS ub", adVarChar, adParamInput, 4, txtPostCodeSub)
cmd.Parameters. Append cmd.CreateParam eter("PhoneNo", adVarChar, adParamInput, 12, txtPhoneNo)
cmd.Parameters. Append cmd.CreateParam eter("LocalTran sport", adVarChar, adParamInput, 200, memoLocalTransp ort)
cmd.Parameters. Append cmd.CreateParam eter("Leisure", adVarChar, adParamInput, 200, memoLeisure)
cmd.Parameters. Append cmd.CreateParam eter("School", adVarChar, adParamInput, 200, memoSchool)
cmd.Parameters. Append cmd.CreateParam eter("Rules", adVarChar, adParamInput, 200, memoRules)
cmd.Parameters. Append cmd.CreateParam eter("Result", adInteger, adParamOutput) ' OutPut Returns Result Parameter a Value

cmd.Execute

Res = cmd("Result")

If (Res = 1) Then
MsgBox "Family Inserted Successfully", , "Insert Family"
End If

Set cmd.ActiveConne ction = Nothing


End Sub

Apologise for wasting your time if this something obvious, but like I say I'm learning.
Dec 19 '06 #1
2 4370
scripto
143 New Member
pretty simple - in your stored procedure immediately after the line values(.....) do this: set @retval = @@IDENTITY

that will automatically put the new ID into the variable @retval. Then you can do
Set @RESULT = @retval
Dec 19 '06 #2
almaz
168 Recognized Expert New Member
pretty simple - in your stored procedure immediately after the line values(.....) do this: set @retval = @@IDENTITY

that will automatically put the new ID into the variable @retval. Then you can do
Set @RESULT = @retval
scope_identity( ) function is a better choice than @@IDENTITY as there might be some triggers defined on tblWfsFamilyDet ails table.
Dec 20 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
261
by: Alberto | last post by:
The following example works, but the retrival of the returned identity does not work 'Set Command Object Propertie objCommand.ActiveConnection = GV_objConnectio objCommand.CommandText = "DAO.RCCBABY_Add_Test objCommand.CommandType = ADODB.CommandTypeEnum.adCmdStoredPro 'Set The Parameter objCommand.Parameters.Append(objCommand.CreateParameter("TestKey", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamReturnValue)...
7
1500
by: Rob Meade | last post by:
Hi all, Just spent an hour and a half trying to get something to work when we realised we had the same problem over a year ago... I have an ASP page which calls a stored procedure, all the stored procedure does is write 4 values to a table, and then returns the identity of the just inserted row, syntax as follows: CREATE PROCEDURE spAddLink
4
41589
by: brent.ryan | last post by:
How do I get the next int value for a column before I do an insert in MY SQL Server 2000? I'm currently using Oracle sequence and doing something like: select seq.nextval from dual; Then I do my insert into 3 different table all using the same uniqueID. I can't use the @@identity function because my application uses a connection pool and it's not garanteed that a connection won't be used
3
1700
by: Mark | last post by:
Hi, I'm having a bit of difficulty in getting the identity of a new row using the SCOPE_IDENTITY() function in SQLServer 2000. I've added the following code: 'set @LastID = SCOPE_IDENTITY()' to the end of the select statement in the Stored Procedure, and have the following code in the aspx.cs file: SqlCommand cmdEntry; SqlParameter prmEntryID = new
4
5078
by: jay | last post by:
I am using the dataset object to add a row to a sql server database in vb.net code, as follows: dim drow as DataRow dim cmdBld as new SqlCommandBuilder(mySqlDataAdapter) ds.tables(0).NewRow() drow("field1") = data for field 1 and so forth ds.tables(0).rows.add(drow) cmdBld = New SqlCommandBuilder(mySqlDataAdapter)
7
3457
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function 'UpdateRegistrant' expects parameter '@EMail', which was not supplied. The field value was null in the database and not changed in the FormView so is null going back into the stored procedure. I'm stumped and would greatly appreciate any suggestions.
3
2845
by: Susanne Klemm | last post by:
Hello! I use a procedure to insert a new row into a table with an identity column. The procedure has an output parameter which gives me the inserted identity value. This worked well for a long time. Now the identity value is over 700.000 and I get errors whiles retrieving the inserted identitiy value. If I delete rows and reset the identity everything works well again. So I think it is a data type problem. My Procedure:
13
3426
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end of the form which is submit and cancel. After i have clicked submit, the information is stored directly into my corresponding database table. My problem here is i need to retrieve back the information submitted to display all the data that the...
5
25563
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim tbl As New DataTable Dim col As DataColumn Dim x As Integer Dim colName(99) As String Dim colType(99) As String cn.Open() tbl = cn.GetSchema("Orders") 'Orders is a table in the
0
8675
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
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
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
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
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
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
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
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.