title: Create a user defined table type in c# to use in sql server stored procedure
body: <p>I'm trying to write a C# program which creates a whole table to send back to a SQL Server stored procedure.</p>
  
  <p>I came across the msdn guide but became incredibly confused:
  <a href="http://msdn.microsoft.com/en-us/library/cc879253.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/cc879253.aspx</a></p>
  
  <p>I tried to use the msdn guide but get an error despite adding references to microsoft.sqlserver.smo, microsoft.sqlserver.connectioninfo, microsoft.sqlserver.management.sdk.sfc as suggested by the compiler. The error is:</p>
  
  <blockquote>
    <p>Set parent failed for userdefinedtabletype.</p>
  </blockquote>
  
  <p>Code snippet based on msdn guide:</p>
  
  <pre><code>Server srv = new Server();
  Database db = srv.Databases["MyDatabase"];
  
  //fails at this line
  UserDefinedTableType udtt = new UserDefinedTableType(db, "TestTable");
  udtt.Columns.Add(new Column(udtt, "Col1", DataType.Int));
  udtt.Create();
  </code></pre>
  
  <p>I would simply like to be able to build a user defined data table, the only related questions I've found here deal only with creating a user defined table in SQL, not C#.</p>
  
  <p>My SQL Server connection code is this:</p>
  
  <pre><code> DataSet ds = new DataSet("SQLDatabase");
  
         using (SqlConnection conn = new SqlConnection(Settings.Default.SQLConnectionString))
         {
             SqlCommand sqlComm = new SqlCommand("StoredProcedure", conn);
  
             sqlComm.Parameters.AddWithValue("@param", paramValue);
  
             sqlComm.CommandType = CommandType.StoredProcedure;
  
             SqlDataAdapter da = new SqlDataAdapter();
             da.SelectCommand = sqlComm;
             da.Fill(ds);
         }
  </code></pre>
  
  <p>Please could someone show me in simple language, how to create a user defined table type in my C# program?</p>