Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your destination is a SQL 2008 database and you're set on using C# to connect to the source and get the data you could use a Table parameter. A DataTable in .NET is directly mappable to a User Defined Table type in SQL Server.</p> <p>Here is a SO thread about it:</p> <p><a href="https://stackoverflow.com/questions/1030848/how-to-pass-user-defined-table-type-as-stored-procedured-parameter-in-c-sharp">How to pass User Defined Table Type as Stored Procedured parameter in C#</a></p> <p>Define your custom table type in your destination database</p> <pre><code> create type MyCustomTable as Table ( Field1 int, Field2 varchar(50), Field3 decimal(18,0) ) </code></pre> <p>The concept would be to read all of the data from the source in to a data table. Then you would use a SqlParameter to execute a stored procedure or possibly text query on your destination server. By using a stored procedure that accepts a table parameter you could do the following:</p> <pre><code> CREATE PROCEDURE dbo.BulkCopyData ( @SourceData MyCustomTable readonly --readonly has to be there, Table params have to be readonly as parameters ) AS BEGIN INSERT INTO dbo.DestinationTable ( Field1, Field2, Field3 --more fields ) SELECT Field1,Field2,Field3 FROM @SourceData END </code></pre> <p>And in C# when you go to execute the command:</p> <pre><code>DataTable dt = new DataTable(); //Go get the data from your source here SqlConnection conn = new SqlConnection("...."); conn.Open(); SqlCommand cmd = new SqlCommand("dbo.BulkCopyData",conn) cmd.Parameters.Add( new SqlParameter("SourceData", SqlDbType.Structured){ TypeName = "dbo.MyCustomTable ", Value = dt}); cmd.Parameters[0]. cmd.ExecuteNonQuery(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload