Hi

I would like to save one table's data to another table. The code that I have wrote is this:

con.Open();
string copyData = "INSERT INTO Changes(IP,ServerName,[Type of Server])SELECT    IP,Server,Name FROM Server";
cmd = new SqlCommand(copyData, con);
int returnValue = cmd.ExecuteNonQuery();
con.Close();

and it seemed working but when I write code to insert new data into the second table called Changes.dbo the data that I enter when I debug the duplicated.

con.Open();
string copyData = "INSERT INTO Changes(IP,ServerName,[Type of Server])SELECT IP,Server,Name FROM Server";
cmd = new SqlCommand(copyData, con);
int returnValue = cmd.ExecuteNonQuery();
con.Close();

its obviouse theat you are trying to insert more times same data, you should try to select data from existing table with NOT IN command, that means you would select only data which are not entered in second table.
SELECT IP,Server,Name FROM Server where IP NOT IN Server 2

Hi

I would like to save one table's data to another table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.