Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 June 17th, 2005, 10:12 AM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting mulitible rows in one table at one time

Hi,

I am having problem with inserting multiple rows in one table at one time submit.

I Have a ASP Form with

First Name
Last Name

Organization 1
Organization 2
Organization 3

I like to insert this form into one table. Table should look like this..

         FName LName Organization
------------------------------------------------------
Row 1 - First Name Last Name Organization1
Row 2 - First Name Last Name Organization2
Row 3 - First Name Last Name Organization3

I need a code to do this functionality. Much appreciated you help.

Thanks
Raj



Mohanraj
 
Old June 21st, 2005, 10:09 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

The way you are trying to do this needs to have three insert statements. However, you are not creating a very efficient database this way.

The best way to do this is to create separate tables, one for personal information, last name, first name, etc. and then create another table with organizations. Of course, unless you want to just create a table with three organization columns, Org1, Org2, and Org3. Then you will be limited to only three orgs if that's what you want.

What you can do with the tables below is when you insert into the personal info table, grab the @@identity and use it to insert the organizations into the Organizations table.

SQL = "Set nocount off;INSERT into PersonalInfo (FirstName, LastName) Values ('" & varFirstName & "', '" & varLastName & "');Select PersonalID = @@Identity;Set nocount on;"

Set oRS = oConn.Execute(SQL)
varPersonalID = oRS("PersonalID")

i = 1
Do Until i = 3

If len(varOrg & i) > 0 Then
SQL = "Insert into Organizations (PersonalID, Organization) VALUES (" & varPersonalID & ", '" & varOrg & i "');"
oConn.Execute(SQL)
i = i + 1
Loop

This way you're not limited to organizations. I don't see any other way than to loop through the records but I'm no expert.


CREATE TABLE [PersonalInfo] (
    [PersonalID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
    [FirstName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [LastName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    CONSTRAINT [PK_PersonalInfo] PRIMARY KEY CLUSTERED
    (
        [PersonalID]
    ) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [Organizations] (
    [OrgID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
    [PersonalID] [int] NULL ,
    [Organization] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    CONSTRAINT [FK_Organizations_PersonalInfo] FOREIGN KEY
    (
        [PersonalID]
    ) REFERENCES [PersonalInfo] (
        [PersonalID]
    ) ON DELETE CASCADE ON UPDATE CASCADE
) ON [PRIMARY]
GO


Hope this helps.

Richard







Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview and inserting rows thewoodchuck BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 April 10th, 2008 09:55 AM
Passing and Inserting mutliple rows at once SQLScott SQL Server 2005 4 February 12th, 2007 11:10 AM
page take time to load after adding rows in table avanishp General .NET 5 June 21st, 2005 02:32 PM
Problem while inserting rows!! raman1 PHP Databases 0 April 16th, 2005 12:03 AM
creating a table and inserting rows. sasidhar79 Classic ASP Databases 2 July 28th, 2004 03:09 AM





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