Hi
Does anyone have any experience of SQL Insert Statement. I have the below statement in one of my ASP projects. The first time the user executes the statement it works as intended and creates one entry into the corresponding table, but if the same user attempts to insert another new record into the same table again it duplicates the insert entry and you end up with three entries all in all in that table for the specific user and so on? i.e.
ATTEMPT ONE
Record 1
ATTEMPT TWO
Record 2
Record 2 COPY
ATTEMPT THREE
Record 3
Record 3 COPY
Record 3 COPY
Code:
Dim connection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("LiteratureCataloguingConnectionString").ConnectionString)
Dim sql As String = "INSERT INTO Loan (PublicationID, UserId, StartLoanDate, EndLoanDate, ThirdDayNotification, FifthDayNotification, FifteenthDayNotification, ThirtiethDayNotification) VALUES (@PublicationID, @UserId, @StartLoanDate, @EndLoanDate, @ThirdDayNotification, @FifthDayNotification, @FifteenthDayNotification, @ThirtiethDayNotification)"
Dim command As SqlCommand = New SqlCommand(sql, connection)
command.Parameters.AddWithValue("@PublicationID", PublicationID)
command.Parameters.AddWithValue("@UserId", UserId)
command.Parameters.AddWithValue("@StartLoanDate", SDate)
command.Parameters.AddWithValue("@EndLoanDate", FDate)
command.Parameters.AddWithValue("@ThirdDayNotification", (0))
command.Parameters.AddWithValue("@FifthDayNotification", (0))
command.Parameters.AddWithValue("@FifteenthDayNotification", (0))
command.Parameters.AddWithValue("@ThirtiethDayNotification", (0))
command.Connection.Open()
command.ExecuteNonQuery()
command.Connection.Close()