Recuperer 1 variable dans un trigger

Résolu
bootchoz Messages postés 88 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 17 septembre 2006 - 9 juin 2006 à 09:35
bootchoz Messages postés 88 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 17 septembre 2006 - 16 juin 2006 à 11:22
bonjour,
je debute en c# et je n'arrive pas a recuperer la valeur d'une variable @id_pers pour l'inserer dans une table via un trigger.
voici le code de ma page .aspx
<

asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:projetConnectionString1 %>
"
InsertCommand
="INSERT INTO [personne] ([wwid_pers], [nom_pers], [id_resp]) VALUES (@wwid_pers, @nom_pers, @id_resp)"
ProviderName="<%$ ConnectionStrings:projetConnectionString1.ProviderName %>
"
SelectCommand
"SELECT personne.id_pers, [wwid_pers], [nom_pers], [id_resp] FROM [personne], [fonction], [a_com_fonc] WHERE fonction.id_fonca_com_fonc.id_fonc AND a_com_fonc.id_pers=personne.id_pers AND [nom_fonc]='signataire'">

voici le code généré par le trigger :

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [insert_sign] ON [dbo].[personne]
FOR INSERT
AS
DECLARE @id_pers bigint
INSERT INTO a_com_fonc
(id_pers, id_fonc) VALUES (@id_pers, 3)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

4 réponses

bootchoz Messages postés 88 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 17 septembre 2006
16 juin 2006 à 11:22
ce message a aussi été posté à cette addresse et j'ai eu la réponse à ma question. Un grand merci à vous tous !http://www.aspfr.com/infomsg_RECUPERER-VARIABLE-DANS-TRIGGER-CSHARP_756191.aspx#9 
3
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
9 juin 2006 à 09:37
tu devrais poser ta question sur le forum asp.net

--> http://www.aspfr.com

Sébastien FERRAND (
blog)
Consultant Indépendant
[Microsoft MVP Visual C#]
0
bootchoz Messages postés 88 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 17 septembre 2006
9 juin 2006 à 09:40
uuups, j'ai oublié de vous dire le message d'erreur qu'il me met :
Cannot insert the value NULL into column 'id_pers',...

merci de votre aide !
0
bootchoz Messages postés 88 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 17 septembre 2006
15 juin 2006 à 09:33
me revoilà avec mon soucis un peu different cette fois car j'ai essayé avec une procédure :

CREATE PROCEDURE InsertAdmin


 AS


DECLARE @id_fonc bigint
DECLARE @id_pers bigint
DECLARE @wwid_pers bigint
DECLARE @nom_pers varchar(50)
DECLARE @id_chef_pers bigint




INSERT INTO [personne] ([id_pers], [wwid_pers], [nom_pers], [id_chef_pers]) VALUES ('', @wwid_pers, @nom_pers, @id_chef_pers)


SET @id_fonc=(SELECT id_fonc FROM fonction WHERE nom_fonc='administrateur')
SET @id_pers=(SELECT MAX(id_pers) FROM [personne])


INSERT INTO a_com_fonc
(id_pers, id_fonc) VALUES (@id_pers, @id_fonc)
GO

je l'insere dans ma page.aspx comme ceci :
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>
" InsertCommand="InsertAdmin"
InsertCommandType="StoredProcedure" />


<asp:LinkButtonID="InsertButton" runat="server"CausesValidation="True"CommandName="Insert" Text="Insert">

le message d'erreur est le suivant :Procedure InsertAdmin has no parameters and arguments were supplied

j'ai essayé en les ecrivant : CREATE PROCEDURE InsertAdmin @id_pers bigint, @wwid_pers bigint, @nom_pers varchar(50), @id_chef_pers bigint
le nouveau message d'erreur est :Cannot insert explicit value for identity column in table 'personne' when IDENTITY_INSERT is set to OFF.
Violation of PRIMARY KEY constraint 'PK_a_com_fonc'. Cannot insert duplicate key in object 'a_com_fonc'.

can anybody help me ??? please... 
0
Rejoignez-nous