Israel

Israel

  • 698
  • 1.3k
  • 217k

Doesnt send records from a Table to another Table

Dec 11 2018 2:45 PM
Hi,
I am sending a couple of records from one Table to another one. But when I run these codes its showing me in runtime a error message like this:
Additional information: Incorrect syntax near the keyword 'IN'. 
 
I need to resolv this situation please.
 
string myConnectionString;
myConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\Database1.mdf; Integrated Security = True";
using (var con = new SqlConnection())
{
con.ConnectionString = myConnectionString;
con.Open();
using (var cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @"INSERT INTO test2 IN 'C:\Copy_table_to_table\WindowsFormsApplication1\database1.mdb' " + @"SELECT * FROM test1";
cmd.ExecuteNonQuery();
}
con.Close();
}
Console.WriteLine("It's done!");
}
 

Answers (4)