Data inserting twice to DB

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

Can anybody tell me what i'm doing wrong?
The data is inserting 2 records at a time!!!
Thanks

Dim conn As SqlConnection
Dim cmdcommand As SqlCommand
Dim param As SqlParameter
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

conn = New
SqlConnection("server=(local);database=Wintergreen;integrated
security=true;")
conn.Open()
txtuser.ID = Request.ServerVariables("LOGON_USER")

cmdcommand = New SqlCommand("rote", conn)
cmdcommand.CommandType = CommandType.StoredProcedure

param = cmdcommand.Parameters.Add("ReturnValue", SqlDbType.Int)

param.Direction = ParameterDirection.ReturnValue
cmdcommand.Parameters.Add("@username", txtuser.Name)


cmdcommand.ExecuteNonQuery()

Label1.Text = "Thanks for filling Crazy John's Survey!"

conn.Close()

End Sub

Sprocedure
-----------
CREATE PROCEDURE rote
(@username varchar(50))
AS
INSERT INTO survey
(username,DateCreated)
VALUES (@username,getdate())
GO
 
F

Fahad Anwar

I think its the Post Back Event that do double insertion.
So in
Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
if Not (Page.PostBack) then
//write the insertion here
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top