i need little this. stored procedure below doesn't seem ever match exiting unique identifier
alter procedure [dbo].[spinsertupdatethisstuff] @id uniqueidentifier output, @content nvarchar(255) begin set nocount on; declare @taudit table (id uniqueidentifier) if exists(select * [dbo].[mydata] [id] = @id) -- update begin update [dbo].[mydata] set [id] = @id, [content] = @content output inserted.[id] @taudit [id] = @id select id @taudit end else begin -- insert set @id = newid() insert [dbo].cbdata ([id], [content]) output inserted.[id] @taudit values(@id, @content) select id @taudit end; set @id = (select id @taudit); end
the c#
cmd.parameters.add("@id", sqldbtype.uniqueidentifier).value = (currentrecord.id == null) ? guid.empty : currentrecord.id; cmd.parameters["@id"].direction = parameterdirection.output; cmd.executenonquery(); currentrecord.id = guid.parse(cmd.parameters["@id"].value.tostring());
it seems first if statement not ever become true, if test (select * [dbo].[mydata] [id] = @id
) matching uid comes data.
this statement problematic,,
declare @taudit table (id uniqueidentifier) if exists(select * [dbo].[mydata] [id] = @id) -- update begin
@id
output parameter , null default , trying check that..
basically newid()
won't duplicated,so update part redundant
Comments
Post a Comment