#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    INSERT multiple records at the same time


    Hi,

    I want to insert several records at the same time from a form (asp/Ms SQL)

    I have in this form a list of football players and checkboxes in order to choose if they have played or not.


    So when form is submitted it have to store in a table, idplayers and idmatch value (hidden form value).
    That could be used to list players by match

    How can i do it?

    I ve made an asp page listing the players with player's id ans check box for each player to choose or not.



    Please help?

    Thanks a lot
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,436
    Rep Power
    4539
    Start by visiting the documentation for the INSERT command for your db, which will show you how you need to write the SQL for the insert.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    46
    Rep Power
    5

    Insert multiple rows in single query using TSQL


    To insert multiple rows with the help of single query you can use following syntax:

    Code:
    Insert
      Into daTable
         ( col1, col2, ... coln )
    values
         ( '21',   9,  ... 'oh' )
        ,( '22',  37,  ... 'my' )
        ,( '23',  42,  ... 'we' )
        ,( '24',  11,  ... 'be' )
        ,( '25',  77,  ... 'at' );
    Code:
    INSERT INTO Table1 (FirstColumn, SecondColumn)
    SELECT 'First' ,1
    UNION ALL
    SELECT 'Second' ,2
    UNION ALL
    SELECT 'Third' ,3
    UNION ALL
    SELECT 'Fourth' ,4
    UNION ALL
    SELECT 'Fifth' ,5
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0
    Hai, you can use sqlbulkcopy class in asp.net to insert multiple values.

IMN logo majestic logo threadwatch logo seochat tools logo