Rajneesh Chaubey

Rajneesh Chaubey

  • NA
  • 2.9k
  • 224.9k

How to insert multiple records in sql?

Feb 13 2018 9:29 AM
I have 3 tables Client, Product and Transaction. 
 Client table has ClientID is (identity)    
  1. ClientID Clientname Email Mobile    
 Product has ProductID(Identity)
  1. ProdID ClientID  Prodname  
Transact  table has TransactID(Identity)
  1. TransactID      ProdID         ClientID      ParamID  
ParamID is the value of those chechboxes.
I want to insert multiple product against single client. Let say there is another button to insert Product(Before Final Insert). On that button we store multiple data on button click in DataTable. It will hold data till we finnaly submit the form. For every Product there can multiple selection of checkbox.
 Now final insert will be like that Client details will go to  the client tables, and for product say
he has inserted two product:p1 and p2 it will goes to product and take particular client id. Like this:-
  1.  ProdID ClientID Prodnam  
  2. 1       1          p1  
  3. 2       1          p2  
So 2 rows will be affected. 
And In transaction table (the most confusing one) multiple rows will be affected such that:
 
  1. TransactID          ProdID          ClientID     ParamID  
  2.    1                  1               1           2  
  3.    2                  1               1           3  
  4.    3                  2               1           1  
  5.    4                  2               1           4  
ParamID indicates that for value of particular checkbox against that product.
So there is multiple rows to be affected in sql server. How do I handle the same in C# codebehind?
I am confused. Please suggest me. Any help would be greatly appreciated. Thank you.

Answers (8)