0

I would like to pass a List<> of object say List<Student> to the parameter of stored proc and have the data stored in corresponding fields in the database. How can I do this? I use SQL Server 2005.

So if the database Table has fields StudentId,Name,Age and the object List<Student> has the same properties containing the data, then the data should go to the corresponding fields in Table.

Please advice with code. Thanks in advance.

Frenz
  • 687
  • 1
  • 10
  • 22
  • Pretty sure you can't do that. You'd have to make a function of your own that accepts such a list and calls the stored procedure once for each item in it. – George T Aug 06 '14 at 11:00
  • You would be better of iterating the List and inserting one at a time. – Max Aug 06 '14 at 11:01
  • You will need a function to make a string (member1, member2...) from you list. than you can pass this string as parameter to SP. SQL Query should be like 'select * from table where students in ( @ parameter )' – Almazini Aug 06 '14 at 11:05

1 Answers1

0

we can pass List by convert it in to XML and pass as parameter Passing lists to SQL Server 2005 with XML Parameters