2010-09-24 6 views
0

Comment puis-je obtenir le paramètre d'identité de portée dans mon code vb? J'ai ce jusqu'à présent ....Obtenir la valeur retournée par scope_identity

InsertCommand="INSERT INTO [table_name] ([title], [subtitle], [description], [image1], [image1_caption], [image2], [pdf], [meta_description], [meta_keywords]) VALUES (@title, @subtitle, @description, @image1, @image1_caption, @image2, @pdf, @meta_description, @meta_keywords); SELECT @NewID = SCOPE_IDENTITY()" 

<asp:Parameter Direction="Output" Name="NewID" Type="Int32" /> 

Comment puis-je retreive cet ID, dans le DetailsView1_ItemInserted?

Si vous avez besoin de plus d'infos faites le moi savoir.

Merci

Répondre

0

Est-ce que vous essayez ceci dans le gestionnaire d'événements ItemInserted?

Sub EmployeeDetailsSqlDataSource_OnInserted(sender As Object, e As SqlDataSourceStatusEventArgs) 
    Dim command As System.Data.Common.DbCommand = e.Command 
    EmployeesDropDownList.DataBind() 
    EmployeesDropDownList.SelectedValue = _ 
     command.Parameters("@NewID").Value.ToString() 
    EmployeeDetailsView.DataBind() 
End Sub 

Vous ne savez pas si vous avez besoin de l'attribut Parameter Direction.

Découvrez cet article MSDN, ils font exactement ce que vous essayez.

http://msdn.microsoft.com/en-us/library/xt50s8kz(VS.80).aspx