Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

The business scenario is that we exposed a web service that is being called by the biztalk server that passes the XML string as an input parameter.

We deserialize the XML string into class object. The main object will have individual properties including the list object.

For Example, Lets assume that class structure is as below.
C#
Class ClassInfo
{
    public string ClassNumber{get;set;}
    
    public string ClassName{get;set}
    
    public List<student> StudentList{get;set;}
    
    public List<professor> ProfessorsList{get;set;}

} 

Lets assume that I would need to insert ClassNumber and ClassName to one table, kind of a new look value, and StudentList and ProfessorsList to two different tables..

If I were to insert multiple rows into a table( StudentList and ProfessorsList list multiple tables) from ADO .NET, I see the following scenarios, I would like to know if there is any better approach than this.... Also, I would like to pass all the parameters as an input parameters to the stored procedure that does the insertion for me.

1. Calling SP inside for each loop for each student and professor.
2. passing collection to SP using table type parameter.
Posted
Updated 12-Nov-15 3:40am
v3

1 solution

Using SqlBulkCopy (example[^]) is one way of doing a bulk insert.
Another option could be using an xml file - Bulk insert into sql database using xml file[^].
 
Share this answer
 
v2
Comments
Ravindranath.net 12-Nov-15 13:51pm    
With the SqlBulkCopy, we can only insert data into one table at a time. My requirement is that, I would like to bulk insert the data into multiple tables at the same time. Meaning, I would like to insert multiple rows into Student and Professors tables at the same time.
Abhinav S 12-Nov-15 23:57pm    
XML can be used. Though writing into two tables with large column sets can become cumbersome.
Ravindranath.net 13-Nov-15 10:52am    
otherthan xml?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900