Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2011, 01:43 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Insert statement?

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()
 
Old May 5th, 2011, 02:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is this all the relevant code? I see no reason why this code would insert multiple records, so the problem is likely elsewhere...

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert statement Banishah ASP.NET 3.5 Basics 1 August 9th, 2009 01:51 PM
Autonumber and insert into statement. rupen Access VBA 1 July 27th, 2007 02:23 PM
Insert Statement Iashia06 Access 0 April 7th, 2006 12:45 PM
How do you execute a Insert statement? brendan82 Beginning VB 6 3 December 29th, 2003 12:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.