Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe you can just do something like:</p> <pre><code>INSERT INTO dbo.tblCourse(list of columns) SELECT (list of columns) FROM dbo.tblCourse WHERE (your condition here.....) </code></pre> <p>Of course, the list of columns must match, e.g. you have to have the same number of columns, and the same datatypes. Also, you cannot insert values into e.g. <code>IDENTITY</code> or computed columns.</p> <p><strong>Update:</strong> to do this in Linq-to-SQL, you'd have to have an entity that can represent your data in some way. Then:</p> <ul> <li>select the data from your existing database into a <code>List&lt;Entity&gt;</code> (or whatever your entity is really called)</li> <li>create new objects (entities) based on those retrieved - change your properties as needed</li> <li>insert those entities back into the data context</li> <li>save the changes.</li> </ul> <p>Something along the lines of this code snippet (here I have a table <code>countries</code> which has an <code>ISOCode</code> and a <code>CountryName</code> for some countries; I'm selecting a few, and creating new ones based on those retrieved, adding those new ones to the Linq-to-SQL <code>DataContext</code> and saving in the end):</p> <pre><code>// create and use the Linq-to-SQL DataContext using (LinqSampleDataContext ctx = new LinqSampleDataContext()) { // select some data IQueryable&lt;country&gt; existingCountries = ctx.countries.Where(c =&gt; c.CountryID &lt; 100); // loop over selected data - create new entities based on data retrieved foreach (country c in existingCountries) { country newCountry = new country(); newCountry.CountryName = c.CountryName; newCountry.ISOCode = "X" + c.ISOCode.Substring(1); // add new entities to DataContext ctx.countries.InsertOnSubmit(newCountry); } // submit all the changes ctx.SubmitChanges(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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