我正在使用Scope_Identity()
,我无法弄清楚为什么在插入时没有检索到新的ID值。我希望有人能看到我所缺少的东西。我收到以下错误:
Uncaught Sys.WebForms.PageRequestManagerServerErrorException:Sys.WebForms.PageRequestManagerServerErrorException:在集合中找不到参数'@urlid'。
以下是我正在使用的SqlDataSource
:
<asp:SqlDataSource id="sqlvoted" runat="server" ConnectionString="<%$ ConnectionStrings:Mym6pConnection %>"
ProviderName="MySql.Data.MySqlClient">
<SelectParameters>
<asp:Parameter Direction="Output" Name="urlid" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
这是click函数内的insert命令(变量声明未显示):
sqlvoted.InsertCommand = "INSERT INTO urls (url,likes,mlsid) VALUES ('" & url & "','" & firstlike.ToString & "','" & newmlsid & "');SELECT SCOPE_IDENTITY() AS @urlid"
sqlvoted.Insert()
dlrecent.DataBind()
这是事件处理程序:
Protected Sub sqlvoted_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles sqlvoted.Inserted
Dim newurlID As Integer = Convert.ToInt32(e.Command.Parameters("@urlid").Value)
End Sub