Data inserting twice to DB

Discussion in 'ASP .Net' started by Patrick Olurotimi Ige, Jan 28, 2005.

  1. 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


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Patrick Olurotimi Ige, Jan 28, 2005
    #1
    1. Advertising

  2. Patrick Olurotimi Ige

    Fahad Anwar Guest

    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
    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    > 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
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Fahad Anwar, Jan 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    415
    Kiuhnm
    Apr 1, 2006
  2. Bhavesh
    Replies:
    0
    Views:
    442
    Bhavesh
    Jul 16, 2007
  3. Bhavesh
    Replies:
    5
    Views:
    664
    Bhavesh
    Jul 18, 2007
  4. Bhavesh
    Replies:
    1
    Views:
    466
    Bhavesh
    Jul 17, 2007
  5. Renie83
    Replies:
    1
    Views:
    189
    Kiran Math
    Jul 10, 2003
Loading...

Share This Page