0

I need to pass a Dictionary> into SQL. I think that table-valued parameters are the best way to go but I'm not entirely sure how to implement them in this case. I obtain values for my dictionary in my script in visual studio, but I will not know what the values will be or how many, until they're displayed in a table. Any help would be greatly appreciated.

Arsenal11
  • 1
  • 1
  • You can use a table-valued parameter and pass your list as a `Structured` parameter. – Aaron Bertrand Jan 14 '15 at 16:47
  • 1
    "Lists" (or "arrays") in SQL Server should always be represented by **rows in a table** - don't use comma-separated hacks or anything like that - those all violate even the **first normal form** of database design! – marc_s Jan 14 '15 at 16:47
  • 1
    @Tab those might be great ideas for < 2008, but not for 2008+ – Aaron Bertrand Jan 14 '15 at 16:47
  • Seems like alot of overhead scraping data from a database only to write it back into the database... why not write a procedure/view to give you the needed data instead of the scraping? (Possibly using temp tables) – xQbert Jan 14 '15 at 16:51
  • My question was actually inaccurate now that I'm looking at my script. I actually need to pass a Dictionary> into SQL. I think that table-valued parameters are the best way to go but I'm not entirely sure how to implement them in this case. – Arsenal11 Jan 14 '15 at 17:15
  • What's unusual about this case that the normal ways of implementing them won't work? – Tab Alleman Jan 14 '15 at 19:01

1 Answers1

0

The following post should lead you in the right direction. You have to create a User Defined Table type, a stored procedure that uses it as a parameter and then create a Data Table in C# that is used as the parameter in ADO.NET.

How to pass table value parameters to stored procedure from .net code

Community
  • 1
  • 1
db_brad
  • 903
  • 6
  • 22