---
title: "Få tag på id med SP och @@identity"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/118746-få-tag-på-id-med-sp-och-identity"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "ironhead"
published: "2004-12-27T10:45:02.000Z"
updated: "2004-12-27T12:24:55.000Z"
replies: 2
views: 286
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/118746-få-tag-på-id-med-sp-och-identity"
---

# Få tag på id med SP och @@identity

## #1 — ironhead, 2004-12-27T10:45Z

Hej!

Jag håller på att bygga en komponent i VB och använder mig av lagrade procedurer och behöver få ut id:t på min INSERT till funktionen:

VB

```
Public Function InsertColl(pConnectionStr As String, pProviderStr As String)
'
'kod
'
   mConnection.Execute ("sInsertColl @sSearchName='" & sSearchName & "'")
    
'
'kod
'     
End Function
```

 

SP:

```
CREATE PROCEDURE sInsertColl
(
@sSearchName varchar(100)
)
AS
BEGIN

SET NOCOUNT ON
 
INSERT INTO RecipeCatCollection(RccName) VALUES(''' + @sSearchName + ''')

Select @@Identity

END
RETURN
```

 

Hur i hela friden får jag tag på Id:t i min funktion?

Permalänk: https://www.webforum.nu/p/118746

## #2 — @nders, 2004-12-27T10:46Z

Du måste skapa ett recordset i din funktion.

```
Public Function InsertColl(pConnectionStr As String, pProviderStr As String)
'
'kod
'
   Dim objRS as ADODB.Recordset
   Set objRS = mConnection.Execute ("sInsertColl @sSearchName='" & sSearchName & "'")
   MsgBox(objRS(0))
'
'kod
'     
End Function
```

Permalänk: https://www.webforum.nu/p/1514577

## #3 — ironhead, 2004-12-27T12:24Z

Tackar...funka klocka :)

Permalänk: https://www.webforum.nu/p/1514639

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/118746-få-tag-på-id-med-sp-och-identity
