Вопрос

I can't figure out why I am getting a double DB entry every time a subroutine is executed. I think I have an idea and I think it is something simple, but I'm not sure how to fix it. Thanks for any assistance anyone can provide.

Here is my datasource:

<asp:SqlDataSource id="sqlvoted" runat="server" ConnectionString="<%$ ConnectionStrings:Mym6pConnection %>"
ProviderName="MySql.Data.MySqlClient">
</asp:SqlDataSource>

And the relevant portion of the sub:

sqlvoted.InsertParameters.Clear()
sqlvoted.InsertCommand = "INSERT INTO urls (url,likes,mlsid,sitename) VALUES ('" & url & "','" & firstlike.ToString & "','" & newmlsid & "','" & sitename & "');SELECT LAST_INSERT_ID()"
sqlvoted.Insert()

And the event handler:

Protected Sub sqlvoted_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles sqlvoted.Inserted
    Dim cmd As System.Data.Common.DbCommand = e.Command
    urllikeID = cmd.ExecuteScalar
End Sub

Am I actually running the insert twice? Once with the sqlvoted.insert() command and once with cmd.ExecuteScalar? That is my best guess but I don't know how to consolidate both into one.

Thanks!

Это было полезно?

Решение

Yes, you are calling twice

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top