Recup l'id

ManuAntibes Messages postés 491 Date d'inscription mardi 24 octobre 2000 Statut Membre Dernière intervention 18 novembre 2021 - 13 avril 2006 à 12:25
cs_Yopyop Messages postés 586 Date d'inscription lundi 7 janvier 2002 Statut Membre Dernière intervention 10 février 2010 - 16 avril 2006 à 16:39
>Salut à tous
>
>Je me permet d'ecrie car je bloc sur du code.
>
>Je souhaite recup l'id de mon INSERT dans une session.
>
>Voici mon code :
>
>
> Private Sub dgclient_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgClient.ItemCommand
>
> Dim sClient As Int32 = ddlPrenom.SelectedItem.Value
> Dim sMagasin As Int32 = Int32.Parse(CType(e.Item.FindControl("dpMagasin"), DropDownList).SelectedValue)
> Dim sDateEntrant As Date = Date.Now
> Dim sDateSortant As Date = CType(e.Item.FindControl("CaldSortant"), Calendar).SelectedDate
>
> Dim sPreparer As String = "0"
> Dim sSortie As String = "0"
> Dim sAnnuler As String = "0"
> Dim Identity As Int32
> Dim sSQL As String = "INSERT INTO ListeCommandeClient(IdClient_LCC, IdMagasin_LCC, DateEntrant_LCC, DateSortant_LCC,Preparer_LCC, Sortie_LCC, Annuler_LCC) values (@Client, @Magasin, @DateEntrant, @DateSortant, @Preparer, @Sortie, @Annuler)SELECT @@IDENTITY AS 'Identity'"
>
> Dim oCon As New Data.SqlClient.SqlConnection(ConnString)
> Dim oComm As New Data.SqlClient.SqlCommand(sSQL, oCon)
> oComm.CommandType = Data.CommandType.Text
>
> oComm.Parameters.Add("@Client", Data.SqlDbType.Int).Value = sClient
> oComm.Parameters.Add("@Magasin", Data.SqlDbType.Int).Value = sMagasin
> oComm.Parameters.Add("@DateEntrant", Data.SqlDbType.DateTime).Value = sDateEntrant
> oComm.Parameters.Add("@DateSortant", Data.SqlDbType.DateTime).Value = sDateSortant
>
> oComm.Parameters.Add("@Preparer", Data.SqlDbType.NVarChar).Value = sPreparer
> oComm.Parameters.Add("@Sortie", Data.SqlDbType.NVarChar).Value = sSortie
> oComm.Parameters.Add("@Annuler", Data.SqlDbType.NVarChar).Value = sAnnuler
>
>
> oCon.Open()
> oComm.ExecuteNonQuery()
> oComm.Dispose()
>
>
> oCon.Close()
>
> Session("ID_Commande") = Identity
> Server.Transfer("CommandeClient_Ajouter1.aspx?ID_Commande")
>
> End Sub
>
>Merci de me donné un coup de main, car mon Identity est vide
>
>Cordialement
>ManuAntibes

4 réponses

cs_poppyto Messages postés 540 Date d'inscription dimanche 29 décembre 2002 Statut Modérateur Dernière intervention 13 mai 2011
13 avril 2006 à 22:48
Il va falloir faire un SELECT après ton INSERT

Poppyto
Cours de basse gratuits avec vidéos et ralentis
Cours de guitare gratuits avec vidéos et ralentis
[%3C/body ]
0
ManuAntibes Messages postés 491 Date d'inscription mardi 24 octobre 2000 Statut Membre Dernière intervention 18 novembre 2021 5
14 avril 2006 à 08:10
Salut Poppyto

mais dans ma ligne INSERT j'ai bien mis un SELECT :


Dim sSQL
As
String =
"INSERT INTO ListeCommandeClient(IdClient_LCC, IdMagasin_LCC, DateEntrant_LCC, DateSortant_LCC,Preparer_LCC, Sortie_LCC, Annuler_LCC) values (@Client, @Magasin, @DateEntrant, @DateSortant, @Preparer, @Sortie, @Annuler) SELECT @@IDENTITY AS 'Identity'"

mais c'est plus apres que je ne sais pas comment continuer le code.


oCon.Open()
oComm.ExecuteNonQuery()
oComm.Dispose()
oCon.Close()


Session(
"ID_Commande") = Identity

merci A+
MANUANTIBES [:p]
0
cs_poppyto Messages postés 540 Date d'inscription dimanche 29 décembre 2002 Statut Modérateur Dernière intervention 13 mai 2011
14 avril 2006 à 09:01
Euh tu es bien sûr qu'il est possible de faire un SELECT juste après l'INSERT (mon bouquin sur SQL n'a pas l'air de connaître .) ?

Poppyto
Cours de basse gratuits avec vidéos et ralentis
Cours de guitare gratuits avec vidéos et ralentis

[</body ]
0
cs_Yopyop Messages postés 586 Date d'inscription lundi 7 janvier 2002 Statut Membre Dernière intervention 10 février 2010 1
16 avril 2006 à 16:39
Salut,

tu fais
oComm.ExecuteNonQuery()

donc normalement ca ne te retourne rien.

Moi, perso, je ferai une transaction :
1. begin transaction
2 . insert
3 . select @@indentity (ou @@SCOPE_IDENTITY)
4. end transaction

yopyop
0
Rejoignez-nous