Tuesday, February 14, 2012

dateadd update works but adds 2 or 3 yrs-not 1

I have a page that is supposed to add a year to a record when it loads. The problem is that it adds 2 or three years instead.
Here is the page_load event:
Sub page_load(sender as object, e as eventargs)
Try
Dim connection As SqlConnection = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim command As SqlCommand = new SqlCommand("Updateexpiredate", connection)
command.CommandType = CommandType.StoredProcedure

Dim param0 As SqlParameter = new SqlParameter("@.memberid",SqlDbType.Int)
param0.Direction = ParameterDirection.Input
param0.Value = memberid
command.Parameters.Add(param0)

connection.Open()
command.ExecuteNonQuery()
connection.Close()
myerror.Text = "Thank You! Your account was updated"
Catch ex As Exception
myerror.Text = ex.Message
End Try
End Sub

And here is the SPROC:
CREATE PROCEDURE Updateexpiredate
(
@.memberid int
)
AS
UPDATE
members
SET
expiredate=(dateadd(year,1,expiredate))<--I also tried expiredate=(dateadd(month,12,expiredate)) with the same results
WHERE
memberID = @.memberID
GO
... I'm assuming you're calling that method or procedure 2 or three time. :)

edited: Step through your app. It could be that it's called multiple times.|||How do I do that?
I don't even know where to begin with that.
Thanks|||The first thing I would do is turn tracing on for the page, and do a trace.write as the command right before the ExecuteNonQuery. This should give you more information on how many times that part of your code is being executed.

If you are not familiar with trace.write, look here:Trace Logging to Page Output. That is a good debugging tool to have in your pocket.

Terri|||What do you use to develop in? Is it Visual Studio, DreamWeaver, WebMatrix, notepad?

No comments:

Post a Comment