title: Going from Dictionary<int, StringBuilder> To Table-Valued SqlParameter. How?
body: <p>I have code that has a Dictionary defined as:</p>
  
  <pre><code>Dictionary&lt;int, StringBuilder&gt; invoiceDict = new Dictionary&lt;int, StringBuilder&gt;();
  </code></pre>
  
  <p>Each Value in each KeyValuePair the Dictionary is actually three separate values currently created as follows: </p>
  
  <pre><code>invoiceDict.Add(pdfCount+i, new StringBuilder(invoiceID.Groups[1].ToString() + "|" + extractFileName + "|" + pdfPair.Key));
  </code></pre>
  
  <p>As you can see, the three values are separated by a '|'. The number of "rows" in the Dictionary can range between 600-1200. I would like to use a table-valued parameter to get all of that in my SQL Server 2008 DB in one operation.</p>
  
  <p>The table-valued parameter is defined as follows:</p>
  
  <pre><code>CREATE TYPE dbo.BatchSplitterInvoices AS TABLE
  (
      InvoiceID varchar(24),
      NotePath varchar(512),
      BatchID varchar(50)
  )
  
  CREATE PROCEDURE dbo.cms_createBatchSplitterInvoices (
    @Invoices dbo.BatchSplitterInvoices READONLY,
    @StaffID int
  )
  </code></pre>
  
  <p>What's the best way to get from the Dictionary to something that can be passed into the table-valued param? Should I use something else than the Dictionary? Or, do I need to parse the Dictionary into another, better data structure?</p>
  
  <pre><code>SqlParameter invoicesParam = cmd.Parameters.AddWithValue("@Invoices", invoiceDict.Values);
  invoicesParam.SqlDbType = SqlDbType.Structured;
  </code></pre>
  
  <p>Thanks.</p>