|
-
Sep 12th, 2001, 03:18 AM
#1
Thread Starter
Member
SQLServer Stored Procedure Problem
Here is the table I'm working with, the primary key is an incremental ID and the table is called ‘Categories’:
CategoryID Primary Key int (4) identity seed 1, identity increment 1
CategoryName varchar (50)
Description varchar (50)
------------------------------------------------
I have created the following stored procedure to insert values into the table (the CategoryID is missing from the stored procedure as it gets created automatically).
“CREATE PROCEDURE [InsertNewCategory]
@CatName VARCHAR(50),
@Desc VARCHAR(50)
AS
BEGIN TRANSACTION
INSERT INTO [Categories]
(
CategoryName,
Description
)
VALUES
(
@CatName,
@Desc
)
COMMIT TRANSACTION”
-----------------------------------------------
I have executed the procedure in VB by using the following code:
VB Code:
Dim rstSave As New ADODB.Recordset
Dim mProcName As String
Screen.MousePointer = 11
If ValidateSave = True Then
If mCatID = 0 Then
mCatName = txtCatName
mDesc = txtDesc
'Procedure name with parameters
mProcName = "InsertNewCategory '" & mCatName & "', '" & mDesc & "'"
'Executes a function in a class to execute the command
If objSQLServer.ExecuteCommand(mProcName) = 0 Then
MsgBox "The new record has been saved to the database"
End If
End If
End If
Screen.MousePointer = 0
The command executes perfectly but the problem I'm having is how to retrieve the CategoryID from the newly created record without having to do another check using the CategoryName and Description as criteria. Is there a way of selecting or outputting the new ID while inserting a new record?
Please help if possible, thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|