about to post I am new to this type of stuff....this is
what I have tried and it isn't working(please note in the
try section I was just trying to see if it was grabbing
my variable or not any suggestions or hints would be
greatly appreciated:
********
Private Sub AddArticle()
Dim sql As String
Dim cmd As SqlCommand
Dim sb As StringBuilder
Dim Values As ArrayList
Dim fNewsDate As String
Dim fNewsSubBy As String
Dim fNewsHdr As String
Dim fNewsDesc As String
Dim NewID
fNewsDate = "'" & txtNewsDate.Text & "',"
fNewsSubBy = "'" & txtNewsSubBy.Text & "',"
fNewsHdr = "'" & txtNewsHdr.Text & "',"
fNewsDesc = "'" & txtNewsDesc.Text & "'"
sql = "SET NOCOUNT ON; Insert INTO [News]
(NewsDate,NewsSubBy,NewsHdr,NewsDesc) Values " & "(" &
fNewsDate & fNewsSubBy & fNewsHdr & fNewsDesc & ");SELECT
@@IDENTITY AS myID FROM News;"
cmd = New SqlCommand(sql, conSCGC)
conSCGC.Open()
Try
cmd.ExecuteScalar()
NewID = cmd.ExecuteScalar("myID")
Response.Write(NewID)
Catch
Response.Write(sql)
Finally
conSCGC.Close()
End Try
End Sub
******
-----Original Message-----
Have you added an output parameter and assigned @@IDENTITY to it? I thinkthat should do it. Alternatively, you could use ExecuteScalar and get theonly SELECTed row, @@IDENTITY.
-mike
MVP
<an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...Thanks but I still have a question..I already had the sql part that wasn't the issue but when I click on the button to submit the link how do I assign the newly added record id to a variable so I can then display a confirm page
with a link to the users newly added record page? I
right now am using the executeNonQuery but it just adds
the record and doesn't return any value.
Thanks>-----Original Message-----
>In the command that inserts, after the insert, you can
do SELECT @@IDENTITY>and that will give you the ID of the last row inserted. >
>-mike
>MVP
>
>"Tony Stoker" <an*******@discussions.microsoft.com>
wrote in message>news:0e****************************@phx.gbl...
>> I have a .Net web app that adds a record to a SQL
>> database. After the user adds their record I want to >> have a link that will link them to their new record!
The>> recordID is a AutoNumber in the SQL server...
>>
>> How do I return the recordID after I have added the
>> record?
>
>
>.
>
.
..