try { cn1 = new SqlConnection(con); if (cn1.State != ConnectionState.Open) { cn1.Open(); } cmd1 = new SqlCommand("Create database " + db + ""); cmd1.Connection = cn1; cmd1.ExecuteNonQuery(); con += ";Driver=SQL Server;database='" + db + "'"; } catch (Exception Ex) { } try { DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb"); DataTable userTables = null; using (connection) { string mappath = dataGridView1.CurrentRow.Cells["Path"].Value.ToString(); string[] filePaths = Directory.GetFiles(@"" + mappath + "", "*.mdb", SearchOption.TopDirectoryOnly); // c:\test\test.mdb foreach (string tr in filePaths) { connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + tr + ""; string[] restrictions = new string[4]; restrictions[3] = "Table"; connection.Open(); userTables = connection.GetSchema("Tables", restrictions); List<string> tableNames = new List<string>(); for (int i = 0; i < userTables.Rows.Count; i++) tableNames.Add(userTables.Rows[i][2].ToString()); try { foreach (string tableName in tableNames) { OleDbCommand cmd = new OleDbCommand("select * into ["+con+"].["+tableName+"] from [" + tableName + "]"); // Got error Here cmd.Connection = connection; cmd.ExecuteNonQuery(); } } catch (Exception Ex) { connection.Close(); } connection.Close(); } } } catch (Exception Ex) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)