获取scope_identity返回值

时间:2010-09-24 14:32:22

标签: asp.net vb.net scope-identity

如何在我的vb代码中获取范围标识参数。到目前为止我有这个....

    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" />

如何在DetailsView1_ItemInserted?

中检索此ID

如果您需要更多信息,请告诉我。

由于

1 个答案:

答案 0 :(得分:0)

您是否在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

不确定您是否需要参数方向属性。

查看此MSDN文章,他们完全按照您的尝试进行操作。

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