I want to use data from the existing table and create a new table using it. I am using local database (.mdf) file to store my data.
I am not able to execute the following line:
SqlCommand com =
new SqlCommand("create table newinfo as (select * from oldinfo)", connection);
Is there any alternative way to create a table in C# from the data selected from another table.
You can use SELECT INTO
:
SELECT * INTO YourNewTable FROM YourOldTable
See more here: https://technet.microsoft.com/en-us/magazine/dd401720.aspx
To create a table from a select statement you use the following syntax
SELECT Field1, Field2, Field3
INTO NewTable
FROM ExistingTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With