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.ToString
If mainid = "" Then mainid = "0"
Dim conn As New System.Data.SqlClient.SqlConnection(SQLstrConn)
Dim sql As String = "uipersonal '" all the variables i send
Dim Cmd As New System.Data.SqlClient.SqlCommand(sql, conn)
Dim objDR As System.Data.SqlClient.SqlDataReader
conn.Open()
If mainid = "0" Then
TextBox1.Text = Cmd.ExecuteScalar
ElseIf mainid > "0" Then
objDR =
Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)
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