/// <summary> /// Copies table from one database to another. /// deletes original table in target /// </summary> /// <param name="filenameSource"></param> /// <param name="filenameTarget"></param> /// <param name="tableName"></param> public static void CopyTable(string filenameSource, string filenameTarget, string tableName) { string sql = "delete * from " + tableName; AccessDB.RunSqlCommand(filenameTarget, sql); AccessDB.InsertTable(AccessDB.ReadTable(filenameSource, tableName), filenameTarget); }
/// <summary> /// Saves Access database table contents to an xml file /// </summary> /// <param name="InputJetfilename"></param> /// <param name="OutputXmlFilename"></param> static void ExportToXML(string InputJetfilename, string OutputXmlFilename) { DataSet myDataSet = new DataSet(); string strAccessConn = GetConnectionString(InputJetfilename); OleDbConnection myAccessConn = new OleDbConnection(strAccessConn); OleDbCommand myAccessCommand = new OleDbCommand(); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand); AccessDB db = new AccessDB(InputJetfilename); string[] tbls = db.TableNames(); try { myAccessConn.Open(); //Console.WriteLine("Closed connection"); if (debugOutput) { Console.WriteLine("Found " + tbls.Length + " tables"); } for (int i = 0; i < tbls.Length; i++) { string tableName = tbls[i]; if (tableName.IndexOf("Paste Errors") >= 0) { continue; } if (debugOutput) { Console.Write(tableName + ":"); } myDataSet.Tables.Add(tableName); string sql = "Select * FROM " + tableName; myDataAdapter.SelectCommand = new OleDbCommand(sql, myAccessConn); //myDataAdapter.Fill(myDataSet,0,1000,tableName); myDataAdapter.Fill(myDataSet, tableName); if (debugOutput) { Console.WriteLine(myDataSet.Tables[tableName].Rows.Count); } } } finally { myAccessConn.Close(); } myDataSet.WriteXml(OutputXmlFilename, XmlWriteMode.WriteSchema); }
/// <summary>executes a sql command </summary> public override int RunSqlCommand(string sql) { return(AccessDB.RunSqlCommand(filename, sql)); }
/// <summary>Saves DataTable </summary> public override int SaveTable(DataTable dataTable, string sql) { return(AccessDB.Save(this.filename, dataTable, sql)); }
/// <summary>Retuns a DataTable</summary> public override DataTable Table(string tableName) { return(AccessDB.ReadTable(filename, tableName)); }
/// <summary>Retuns a DataTable</summary> public override DataTable Table(string tableName, string sql) { return(AccessDB.Table(filename, tableName, sql)); }