Insert Multiple Records by one click
-
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.
-
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.
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
-
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.
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();