bootchoz
Messages postés88Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention17 septembre 2006
-
9 juin 2006 à 09:35
bootchoz
Messages postés88Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention17 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
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" />
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'.