I am trying to read datas from one database table and then add it to another table. This is my example and code.
This is the table I am reading from:

And this is the table when I save it:

This is the code I use:
protected void Button1_Click(object sender, EventArgs e)
{
var db = Database.Open("ConnectionString");
var FJSCR = db.Query("SELECT * FROM [SALESAGENT]");
foreach (var item in FJSCR)
{
Label1.Text += item.CODE;
//Label1.Text += "<hr/>";
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con .Open();
string FJ = "EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'";
FJ = "insert into MAG(COD) VALUES (@COD)";
SqlCommand kom = new SqlCommand(FJ, con);
kom.Parameters.AddWithValue("@COD", Label1.Text);
kom.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write("Error " + ex.ToString());
}
}
}
Any help? Thank You!