Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 November 14th, 2008, 01:37 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default How Not To Insert Duplicate Records

My stored procedure is inserting duplicate records, what I am working on is converting from classic ASP to ASP.NET.
The insertion occurs within the PageLoad Event Handler as the user logs onto the web page, I capture the data to be insert, but it is inserting a new record each time the user access the web page.
My code is:
'Insert New record
 Dim cmdAddRecord As SqlCommand = New SqlCommand
 With cmdAddRecord
 .CommandType = CommandType.StoredProcedure
 .CommandText = "usp_InsertEmployeesTodaysLogin"
 .Parameters.AddWithValue("@UserID", Session("EmployeeID"))
 .Parameters.AddWithValue("@Today", DateTime.Now.ToShortDateString)
 .Parameters.AddWithValue("@SSNLogon", strLogin)
 .Connection = sqlcon
 .Connection.Open()
 .ExecuteNonQuery()
 .Connection.Close()
 .Dispose()
 End With

Thank you.

Gail



 
Old November 14th, 2008, 02:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Did you try with page.ispostback (or a property like that?)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 14th, 2008, 04:31 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, I have:
If Not Page.IsPostBack Then
......


 
Old November 15th, 2008, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

If the SP is working ok, then you are going into that code twice.. Did you try to trace your code???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old November 17th, 2008, 11:30 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default


I looked at the code and the problem is the code is excuting each time the page is loaded. Howeverm, I need the Insert block of code to only excute once for each person that logs onto the page.

If have been trying to find a means to catch the one row count and stop the process-yet to no success.

What would you suggest?

Thanks.

GailCG

 
Old November 25th, 2008, 12:19 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I found the solution.
ALTER PROCEDURE dbo.usp_InsertEmployeesTodaysLogin
(
    @UserID char(8),
    @Today datetime,
    @SSNLogon char(15)
    )
as
BEGIN
    IF NOT EXISTS(select UserID, Today, SSNLogon FROM Tires
        WHERE (UserID=@UserID and Today=@Today and SSNLogon = @SSNLogon))

BEGIN

INSERT INTO Tires
           (UserID, Today, SSNLogon)
VALUES (@UserID,@Today,@SSNLogon)

END

END
RETURN









Similar Threads
Thread Thread Starter Forum Replies Last Post
duplicate records vanitha SQL Server 2000 4 June 2nd, 2007 04:35 PM
duplicate records vanitha Reporting Services 2 May 31st, 2007 01:54 AM
Deleting duplicate records ninel SQL Server 2000 3 June 14th, 2006 02:12 PM
Duplicate Records mrookey Dreamweaver (all versions) 1 April 15th, 2005 11:23 AM
No Duplicate Records Error crapanz PHP Databases 0 September 28th, 2004 07:31 PM





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