Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Insert Multiple Records by one click

Insert Multiple Records by one click

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasevisual-studiotutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sk_ko
    wrote on last edited by
    #1

    Excuse me, I have listbox binded sql datasource. & also I have one two textboxes. now I want to insert listbox items and these textbox values into sql table by one Submit click. for example: the listbox contain 3 items. ListBox: Item 1 Item 2 Item 3 Textbox 1: text1 Textbox 2: text2 I want to insert these above values into sql table, I also want to store priority value in sql table, as in the order of ListBox. as follow: When I clicked Submit button, data will be stored like below; Sql Table1: id | column1 | column2 | column3 | priority | 1 | text1 | text2 | item1 | 1 | 2 | text1 | text2 | item2 | 2 | 3 | text1 | text2 | item3 | 3 | Next Time, when inserted new item values data... Sql Table1 id | column1 | column2 | column3 | priority | 1 | text1 | text2 | item1 | 1 | 2 | text1 | text2 | item2 | 2 | 3 | text1 | text2 | item3 | 3 | 4 | text1 | text2 | item1 | 1 | 5 | text1 | text2 | item2 | 2 | 5 | text1 | text2 | item3 | 3 | How I have to do? I am using VS 2005 in C#. I am developing web project. Thank in advance.

    K R 2 Replies Last reply
    0
    • S sk_ko

      Excuse me, I have listbox binded sql datasource. & also I have one two textboxes. now I want to insert listbox items and these textbox values into sql table by one Submit click. for example: the listbox contain 3 items. ListBox: Item 1 Item 2 Item 3 Textbox 1: text1 Textbox 2: text2 I want to insert these above values into sql table, I also want to store priority value in sql table, as in the order of ListBox. as follow: When I clicked Submit button, data will be stored like below; Sql Table1: id | column1 | column2 | column3 | priority | 1 | text1 | text2 | item1 | 1 | 2 | text1 | text2 | item2 | 2 | 3 | text1 | text2 | item3 | 3 | Next Time, when inserted new item values data... Sql Table1 id | column1 | column2 | column3 | priority | 1 | text1 | text2 | item1 | 1 | 2 | text1 | text2 | item2 | 2 | 3 | text1 | text2 | item3 | 3 | 4 | text1 | text2 | item1 | 1 | 5 | text1 | text2 | item2 | 2 | 5 | text1 | text2 | item3 | 3 | How I have to do? I am using VS 2005 in C#. I am developing web project. Thank in advance.

      K Offline
      K Offline
      kaisernayan
      wrote on last edited by
      #2

      Its really simple. You have to put the insert code into a loop. From your description, suppose your list-box has 5 items. then you can make code like this for(int i=0;i

      1 Reply Last reply
      0
      • S sk_ko

        Excuse me, I have listbox binded sql datasource. & also I have one two textboxes. now I want to insert listbox items and these textbox values into sql table by one Submit click. for example: the listbox contain 3 items. ListBox: Item 1 Item 2 Item 3 Textbox 1: text1 Textbox 2: text2 I want to insert these above values into sql table, I also want to store priority value in sql table, as in the order of ListBox. as follow: When I clicked Submit button, data will be stored like below; Sql Table1: id | column1 | column2 | column3 | priority | 1 | text1 | text2 | item1 | 1 | 2 | text1 | text2 | item2 | 2 | 3 | text1 | text2 | item3 | 3 | Next Time, when inserted new item values data... Sql Table1 id | column1 | column2 | column3 | priority | 1 | text1 | text2 | item1 | 1 | 2 | text1 | text2 | item2 | 2 | 3 | text1 | text2 | item3 | 3 | 4 | text1 | text2 | item1 | 1 | 5 | text1 | text2 | item2 | 2 | 5 | text1 | text2 | item3 | 3 | How I have to do? I am using VS 2005 in C#. I am developing web project. Thank in advance.

        R Offline
        R Offline
        rkrishnach
        wrote on last edited by
        #3

        Build datatable in code behind.Add all rows to the datatable. Then use sqlbulkcopy.It inserts all the records into database table in one shot. SqlConnection destinationConnection = new SqlConnection(strConnection); destinationConnection.Open(); SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection ); bulkCopy.DestinationTableName = "destination"; bulkCopy.WriteToServer(yourDatatable); destinationConnection .Close();

        Rams.Ch

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups