Hi, as you see I have two pieces of codes transfering datas Table1 to Table2.
1) The first piece is transfering datas using MSAccess’s Table. It doing well the job.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string myConnectionString;
- myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Copy_table_to_table\WindowsFormsApplication1\App_Datas\test.mdb;Persist Security Info=False";
- using (var con = new OleDbConnection())
- {
- con.ConnectionString = myConnectionString;
- con.Open();
- using (var cmd = new OleDbCommand())
- {
- cmd.Connection = con;
- cmd.CommandType = System.Data.CommandType.Text;
- cmd.CommandText = @"INSERT INTO test2 IN 'C:\Copy_table_to_table\WindowsFormsApplication1\App_Datas\test.mdb' " + @"SELECT A,B,C FROM test1";
- cmd.ExecuteNonQuery();
- }
- con.Close();
- }
- Console.WriteLine("Done.");
- }
- }
- }
2) The Segond piece is transfering from Table1 to Table2 uing SQLSERVER’s Table. Unfortunatly, its stucking giving this error message: Incorrect syntax near the keyword 'IN'
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- SqlConnection conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf;Integrated Security = True;Integrated Security = True");
- SqlCommand comm;
- SqlDataAdapter da;
- string connstr = @"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf;Integrated Security = True;Integrated Security = True";
- private void button1_Click(object sender, EventArgs e)
- {
- string myConnectionString;
- myConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf; Integrated Security = True; Integrated Security = True";
- {
- conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf; Integrated Security = True; Integrated Security = True");
- if (conn.State != ConnectionState.Open)
- conn.Open();
- using (var cmd = new SqlCommand())
- {
- cmd.Connection = conn;
- cmd.CommandType = System.Data.CommandType.Text;
- cmd.CommandText = @"INSERT INTO test2 IN 'C:\Copy_table_to_table\WindowsFormsApplication1\test.mdf' " + @"SELECT A,B,C FROM test1";
- cmd.ExecuteNonQuery();
- }
- }
- Console.WriteLine("Done.");
- conn.Close();
- }
- }
- }