i've been playing with this code to return an ID on an insert - it seems a
little dirty/hacky to me
stored proc goes something like this (ive stripped out uneccesary sql code -
the proc works fine) :-
CREATE PROCEDURE uipersonal
declare all the variables here
AS
IF EXISTS (SELECT * database WHERE id=@mainid)
UPDATE
ELSE
INSERT
SELECT SCOPE_IDENTITY( )
GO
thats basically the stored proc
my vb code is something like :-
Private Sub putdatain()
mainid = TextBox1.Text.T oString
If mainid = "" Then mainid = "0"
Dim conn As New System.Data.Sql Client.SqlConne ction(SQLstrCon n)
Dim sql As String = "uipersonal '" all the variables i send
Dim Cmd As New System.Data.Sql Client.SqlComma nd(sql, conn)
Dim objDR As System.Data.Sql Client.SqlDataR eader
conn.Open()
If mainid = "0" Then
TextBox1.Text = Cmd.ExecuteScal ar
ElseIf mainid > "0" Then
objDR =
Cmd.ExecuteRead er(System.Data. CommandBehavior .CloseConnectio n)
End If
conn.Close()
End Sub
this works ok but seems a little messy - and i was wondering if this method
would cause issues in the future
(atm its just test code to play around)
thanks
mark