How to add multiple rows in a one shot from C# to a Database table using Sqlcommand

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • btreddy
    New Member
    • Oct 2008
    • 83

    How to add multiple rows in a one shot from C# to a Database table using Sqlcommand

    Hii..,

    I've a form where some 10 textboxes are there with lables along with them.i need to add the lable text and textbox text as a single row to database table.so i've 20 text boxes and 20 lables so i need to add 20 rows.How can i add these many rows in a single shot.

    Thank you.

    Im using C# and VS 2008.

    Rgds,
    Tirumala Reddy B
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    This adds two rows in TableXY

    Code:
    INSERT INTO TableXY
      SELECT 'Row1Val1', 'Row1Val2' UNION
      SELECT 'Row2Val1', 'Row2Val2'

    Comment

    • btreddy
      New Member
      • Oct 2008
      • 83

      #3
      Thanks for the Reply .

      Comment

      • Bryan Cheung
        New Member
        • Nov 2010
        • 55

        #4
        A different way:
        Code:
        INSERT INTO TableName (FieldID, Field1, Field2)
        VALUES (1, 'foo', 'bar'), 
           (2, 'blaa', 'blaat')

        Comment

        Working...