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 February 22nd, 2007, 06:17 PM
Friend of Wrox
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default why is this code executed twice?


this code inserts twice the same record. I thin it is due to the "Selet Scope_Identity" in the sqlcommand.
If i remove the Select part, the inserts occurs only once. If i remove the line "comd.ExecuteNonQuery()", then the inserts also occurs once.

Is there something wrong in my code?


Dim connection As SqlConnection
        Dim comd As SqlCommand
        Dim connectionstr, sql As String
        Dim iden As Integer
        connectionstr =
ConfigurationManager.ConnectionStrings("econn").Co nnectionString.ToString()
        connection = New SqlConnection(connectionstr)
        comd = New SqlCommand()
        comd.Connection = connection
       sql = "INSERT INTO table(field,...) VALUES (@fld,...); SELECT
        comd.Parameters.Add("@var1", SqlDbType.NVarChar, 10).Value =
        iden = Convert.ToInt32(comd.ExecuteScalar())

Old February 23rd, 2007, 06:05 AM
Friend of Wrox
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts

I found it:
the executenonquery command must be removed ...

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript Sub is executed twice.... jaijavan20194 VBScript 4 April 30th, 2009 09:05 PM
external.js not executed cyrus67 Javascript 2 November 17th, 2006 10:29 AM
how to grab and store executed value of url method PHP How-To 0 March 30th, 2006 01:57 PM
IsPostback executed twice amantona ASP.NET 1.0 and 1.1 Professional 3 February 3rd, 2005 08:41 AM
viewing executed programs Jonmark BOOK: Beginning Java 2 4 February 19th, 2004 10:15 AM

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