webForumDet fria alternativet

Problem med dubbelpostning.

1 svar · 278 visningar · startad av ConnyFox

ConnyFoxMedlem sedan aug. 20011 087 inlägg
#1

Av någon anledning så körs min ena stored procedure (insertIMDBmovie) två gånger, medans den andra (insertUserMovie) endast körs en gång (vilket är rätt) någon som kan se problemet?

Sub MySQLDataGrid_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
        Dim intMovieID As Integer
        ' If multiple ButtonField column fields are used, use the
        ' CommandName property to determine which button was clicked.
        If e.CommandName = "Select" Then
            ' Convert the row index stored in the CommandArgument
            ' property to an Integer.
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            ' Get the last name of the selected author from the appropriate
            ' cell in the GridView control.
            Dim selectedRow As GridViewRow = MySQLDataGrid.Rows(index)
            Dim titleCell As TableCell = selectedRow.Cells(1)
            Dim strTitle As String = titleCell.Text

            Dim yearCell As TableCell = selectedRow.Cells(2)
            Dim intYear As String = yearCell.Text

            Dim imdbCell As TableCell = selectedRow.Cells(3)
            Dim strImdbID As String = imdbCell.Text

            ' Define data objects
            Dim conn As SqlConnection
            Dim comm As SqlCommand
            ' Read the connection string from Web.config
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("moviedatabase").ConnectionString
            ' Initialize connection
            conn = New SqlConnection(connectionString)
            ' Create command
            comm = New SqlCommand("insertIMDBMovie", conn)
            ' Specify we're calling a stored procedure
            comm.CommandType = System.Data.CommandType.StoredProcedure
            ' Add command parameters
            comm.Parameters.Add("@title", System.Data.SqlDbType.NVarChar, 150)
            comm.Parameters("@title").Value = strTitle
            comm.Parameters.Add("@year", System.Data.SqlDbType.Int)
            comm.Parameters("@year").Value = intYear
            comm.Parameters.Add("@imdbid", System.Data.SqlDbType.NVarChar, 50)
            comm.Parameters("@imdbid").Value = strImdbID
            Try
                ' Open the connection
                conn.Open()
                ' Execute the command
                comm.ExecuteNonQuery()
               intMovieID = comm.ExecuteScalar

            Catch
                ' Display error message
                dbErrorMessage.Text = "Error submitting the IMDBmovie request! Please Try again later, and/or change the entered data!"
            Finally
                
                conn.Close()
                Label1.Text = "You Added " & Title & "."

            End Try

Dim conn2 As SqlConnection
                Dim comm2 As SqlCommand
                ' Close the connection
                

                conn2 = New SqlConnection(connectionString)
                ' Create command
                comm2 = New SqlCommand("insertUserMovie", conn2)
                ' Specify we're calling a stored procedure
                comm2.CommandType = System.Data.CommandType.StoredProcedure
                ' Add command parameters
                comm2.Parameters.Add("@userID", System.Data.SqlDbType.Int)
                comm2.Parameters("@userID").Value = Session("userID")
                comm2.Parameters.Add("@MovieID", System.Data.SqlDbType.Int)
                comm2.Parameters("@MovieID").Value = intMovieID
                comm2.Parameters.Add("@format", System.Data.SqlDbType.Int)
                comm2.Parameters("@format").Value = movie_formats.SelectedItem.Value.ToString()
                Try
                    ' Open the connection
                    conn2.Open()
                    ' Execute the command
                    comm2.ExecuteNonQuery()
                Catch
                    ' Display error message
                    dbErrorMessage.Text = "Error submitting the usermovie request! Please Try again later, and/or change the entered data!"
                Finally
                    ' Close the connection
                    conn2.Close()
                End Try

        End If

    End Sub
ConnyFoxMedlem sedan aug. 20011 087 inlägg
#2

Kan det ha o göra med scope_identity i min stored procedure?


ALTER PROCEDURE insertIMDBmovie
(
@title nvarchar(150),
@year int,
@imdbID nvarchar(50)
)
AS
INSERT INTO movies (title, year, imdbid)
VALUES (@title, @year, @imdbID); 

Select Scope_Identity()
127 ms totalt · 3 externa anrop · v20260731065814-full.fb544a5a
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
125 ms — hämta tråd, inlägg och bilagor (db)