0

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!

Jared Venema
  • 41
  • 2
  • 8

1 Answers1

0

Yes, you are calling twice

gbn
  • 422,506
  • 82
  • 585
  • 676
  • Thanks, gbn. If you don't mind, can you help me understand how to get rid of one of them? If I remove sqlvoted.Insert() then my event handler is obsolete. But If I remove .ExecuteScalar I don't know how else to pick up the value. I'm on day 3 of trying to figure this out and I'm getting frustrated because I know it is something simple. Thanks. – Jared Venema Apr 25 '13 at 01:49
  • Move the ExecuteScalar to the EventHandler? – gbn Apr 25 '13 at 06:59
  • ExecuteScalar is already in the EventHandler, that's the problem. Without sqlvoted.Insert() I have no event to handle, but without ExecuteScalar I don't know how to pick up the value. This is killing me. – Jared Venema Apr 26 '13 at 01:53