예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
/// <summary>executes a sql command </summary>
        public override int RunSqlCommand(string sql)
        {
            return(AccessDB.RunSqlCommand(filename, sql));
        }
예제 #4
0
 /// <summary>Saves DataTable </summary>
 public override int SaveTable(DataTable dataTable, string sql)
 {
     return(AccessDB.Save(this.filename, dataTable, sql));
 }
예제 #5
0
 /// <summary>Retuns a DataTable</summary>
 public override DataTable Table(string tableName)
 {
     return(AccessDB.ReadTable(filename, tableName));
 }
예제 #6
0
 /// <summary>Retuns a DataTable</summary>
 public override DataTable Table(string tableName, string sql)
 {
     return(AccessDB.Table(filename, tableName, sql));
 }