utorak, 2. lipnja 2009.

How to call Insert Stored Procedure with Output parameter in C#

1 . Stored procedure for Inserting with Output parameter:

ALTER PROCEDURE [dbo].[Insert_Narucitelj]

@NAR_ID_Narucitelja int Output,
@NAR_spol varchar(8),
@NAR_ime varchar(20)

AS

INSERT INTO dbo.Narucitelj ( NAR_Spol, NAR_ime )
VALUES ( @NAR_Spol, @NAR_ime )

SET @NAR_ID_Narucitelja = @@IDENTITY

2. DBML (Database Markup Language) - a LINQ to SQL Classes
Pool table and stored procedure.

3. Calling insert store procedure with output parameter

DataClassesNaruciteljDataContext DCNaruciteljContext = new
DataClassesNaruciteljDataContext();
Narucitelj narucitelj = new Narucitelj();
//definition for output parameter in c#
System.Nullable
<int > nullableID = narucitelj.NAR_ID_Narucitelja;
DCNaruciteljContext.Insert_Narucitelj(ref nullableID, "Zensko", "Fata");