<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>freachable.net - SQL</title>
    <link>http://freachable.net/</link>
    <description>Next generation's garbage</description>
    <language>en-us</language>
    <copyright>Hafthor Stefansson</copyright>
    <lastBuildDate>Fri, 26 Mar 2010 02:54:18 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>blog@freachable.net</managingEditor>
    <webMaster>blog@freachable.net</webMaster>
    <item>
      <trackback:ping>http://freachable.net/Trackback.aspx?guid=21859f16-e104-4e84-ad38-3a118b1ee8e0</trackback:ping>
      <pingback:server>http://freachable.net/pingback.aspx</pingback:server>
      <pingback:target>http://freachable.net/PermaLink,guid,21859f16-e104-4e84-ad38-3a118b1ee8e0.aspx</pingback:target>
      <dc:creator>Hafthor Stefansson</dc:creator>
      <wfw:comment>http://freachable.net/CommentView,guid,21859f16-e104-4e84-ad38-3a118b1ee8e0.aspx</wfw:comment>
      <wfw:commentRss>http://freachable.net/SyndicationService.asmx/GetEntryCommentsRss?guid=21859f16-e104-4e84-ad38-3a118b1ee8e0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font face="Tahoma">
            <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">Wanted
a generic way to pass a DataTable as a parameter to SqlCommand as a TVP (Table Value
Parameter). It automatically creates the, IMHO, superfluous User-Defined Table Types.
Here's what I have so far:</span>
          </font>
          <br />
        </p>
        <pre>
          <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">
            <pre>
              <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">&lt;Runtime.CompilerServices.Extension()&gt;
_ <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span> AddTableParameter(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> cmd <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> SqlCommand, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> n <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">String</span>, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> dt <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DataTable) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Static</span> typeXlat <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> Dictionary(Of
System.Type, SqlDbType) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span> typeXlat <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Is</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Nothing</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span> typeXlat <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> Dictionary(Of
System.Type, SqlDbType) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(Int64),
SqlDbType.BigInt) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(Int32),
SqlDbType.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Int</span>)
typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(Int16),
SqlDbType.SmallInt) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Byte</span>),
SqlDbType.TinyInt) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(SByte),
SqlDbType.TinyInt) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span>),
SqlDbType.Bit) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">String</span>),
SqlDbType.VarChar) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Byte</span>()),
SqlDbType.VarBinary) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(DateTime),
SqlDbType.DateTime) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(DateTimeOffset),
SqlDbType.DateTimeOffset) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Char</span>),
SqlDbType.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Char</span>)
typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Single</span>),
SqlDbType.Real) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Double</span>),
SqlDbType.Float) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Decimal</span>),
SqlDbType.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Decimal</span>)
typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(Guid),
SqlDbType.UniqueIdentifier) typeXlat.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(<span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">GetType</span>(Xml.XmlDocument),
SqlDbType.Xml) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'assembly
the typename and spec</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span> tabletypedef <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> List(Of <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">String</span>) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span> parm <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> SqlParameter(n,
SqlDbType.Structured) parm.Value <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> dt <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">For</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Each</span> c <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DataColumn <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">In</span> dt.Columns <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span> s <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> SqlDbType <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> SqlDbType.Variant <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span> typeXlat.ContainsKey(c.DataType) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span> s <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> typeXlat(c.DataType)
tabletypedef.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(c.ColumnName <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"
"</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span> s.ToString) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Next</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span> tabledef <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">String</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Join</span>(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">","</span>,
tabletypedef.ToArray) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">typename</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"autotype_"</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span> tabledef
parm.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">TypeName</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"["</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">typename</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"]"</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'create
the type if needed</span> Using cmd2 <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> SqlCommand(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"select
count(*) from sys.types where is_table_type=1 and name='"</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">typename</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"'"</span>,
cmd.Connection) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span> cmd2.ExecuteScalar() <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> 0 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span> cmd2.CommandText <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"create
type ["</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">typename</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"]
as table("</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span> tabledef <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">")"</span> cmd2.ExecuteNonQuery() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Using <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'add
the parm referencing the typename</span> cmd.Parameters.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Add</span>(parm) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span></span>
            </pre>
            <br />
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">
            </span>
          </span>
        </pre>
        <p>
        </p>
        <img width="0" height="0" src="http://freachable.net/aggbug.ashx?id=21859f16-e104-4e84-ad38-3a118b1ee8e0" />
      </body>
      <title>Not Texturized Vegetable Protein</title>
      <guid isPermaLink="false">http://freachable.net/PermaLink,guid,21859f16-e104-4e84-ad38-3a118b1ee8e0.aspx</guid>
      <link>http://freachable.net/2010/03/26/NotTexturizedVegetableProtein.aspx</link>
      <pubDate>Fri, 26 Mar 2010 02:54:18 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font face="Tahoma"&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Wanted
a generic way to pass a DataTable as a parameter to SqlCommand as a TVP (Table Value
Parameter). It automatically creates the, IMHO, superfluous User-Defined Table Types.
Here's what I have so far:&lt;/span&gt;&lt;/font&gt; 
&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;lt;Runtime.CompilerServices.Extension()&amp;gt;
_ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; AddTableParameter(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; cmd &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; SqlCommand, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; n &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;String&lt;/span&gt;, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; dt &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DataTable) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Static&lt;/span&gt; typeXlat &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; Dictionary(Of
System.Type, SqlDbType) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; typeXlat &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Is&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Nothing&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; typeXlat &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; Dictionary(Of
System.Type, SqlDbType) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(Int64),
SqlDbType.BigInt) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(Int32),
SqlDbType.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Int&lt;/span&gt;)
typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(Int16),
SqlDbType.SmallInt) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Byte&lt;/span&gt;),
SqlDbType.TinyInt) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(SByte),
SqlDbType.TinyInt) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt;),
SqlDbType.Bit) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;String&lt;/span&gt;),
SqlDbType.VarChar) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Byte&lt;/span&gt;()),
SqlDbType.VarBinary) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(DateTime),
SqlDbType.DateTime) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(DateTimeOffset),
SqlDbType.DateTimeOffset) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Char&lt;/span&gt;),
SqlDbType.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Char&lt;/span&gt;)
typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Single&lt;/span&gt;),
SqlDbType.Real) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Double&lt;/span&gt;),
SqlDbType.Float) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Decimal&lt;/span&gt;),
SqlDbType.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Decimal&lt;/span&gt;)
typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(Guid),
SqlDbType.UniqueIdentifier) typeXlat.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;GetType&lt;/span&gt;(Xml.XmlDocument),
SqlDbType.Xml) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'assembly
the typename and spec&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; tabletypedef &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; List(Of &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;String&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; parm &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; SqlParameter(n,
SqlDbType.Structured) parm.Value &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; dt &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;For&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Each&lt;/span&gt; c &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DataColumn &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;In&lt;/span&gt; dt.Columns &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; s &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; SqlDbType &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; SqlDbType.Variant &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; typeXlat.ContainsKey(c.DataType) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; s &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; typeXlat(c.DataType)
tabletypedef.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(c.ColumnName &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"
"&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; s.ToString) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Next&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; tabledef &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;String&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Join&lt;/span&gt;(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;","&lt;/span&gt;,
tabletypedef.ToArray) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;typename&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"autotype_"&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; tabledef
parm.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;TypeName&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"["&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;typename&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"]"&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'create
the type if needed&lt;/span&gt; Using cmd2 &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; SqlCommand(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"select
count(*) from sys.types where is_table_type=1 and name='"&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;typename&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"'"&lt;/span&gt;,
cmd.Connection) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; cmd2.ExecuteScalar() &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; cmd2.CommandText &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"create
type ["&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;typename&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"]
as table("&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; tabledef &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;")"&lt;/span&gt; cmd2.ExecuteNonQuery() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Using &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'add
the parm referencing the typename&lt;/span&gt; cmd.Parameters.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Add&lt;/span&gt;(parm) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://freachable.net/aggbug.ashx?id=21859f16-e104-4e84-ad38-3a118b1ee8e0" /&gt;</description>
      <comments>http://freachable.net/CommentView,guid,21859f16-e104-4e84-ad38-3a118b1ee8e0.aspx</comments>
      <category>.NET</category>
      <category>SQL</category>
    </item>
  </channel>
</rss>