I want to merge two same name scheme and table but different path. I expected it works but not.
It return error 'System.Data.SqlClient.SqlException: 'Incorrect syntax near 'C:'. Incorrect syntax near 'C:'. The label 'C' has already been declared. Label names must be unique within a query batch or stored procedure.''
private void Merge_Click(object sender, RoutedEventArgs e) {
string x = // same name scheme but different path 1
// c:\dbdata\b.mdf
Files.Items[0].ToString(); //from listbox 1
string y = // same name scheme but different path 2
// c:\dbdata\a\b.mdf
Files2.Items[Files2.SelectedIndex].ToString(); //from listbox 2
string connect = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + x + ";Integrated Security=True;Connect Timeout=30";
string connect2 = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + y + ";Integrated Security=True;Connect Timeout=30;Pooling=False;";
string insert = "INSERT INTO " + x + ".dbo.item" +
" (id, name)" +
// same table name 1
" SELECT id, name" +
"FROM " + y + ".dbo.item"; //same table name 2
string q = @"select * from dbo.item ";
using (SqlConnection connection = new SqlConnection(connect))
{
connection.Open();
using (SqlConnection connection2 = new SqlConnection(connect2))
{
connection2.Open();
SqlCommand commandinsert = new SqlCommand(insert, connection);
var temp = commandinsert.ExecuteReader();
}
}
when i replace
" SELECT id, name
" + "FROM
" + y + ".dbo.item
" to
"values (1, 'a')
" and "INSERT INTO
" + x + ".dbo.item
" to "INSERT INTO dbo.item
" it worked