0

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.

Edited by __avd: Added [code] tags.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by gogolo
0
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

Edited by __avd: Added [code] tags.

0

Hi

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

Edited by gogolo: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.