コード例 #1
0
        /// <summary>
        /// Inspect database and create point table if not found
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        private static bool CheckandCreateTable(string fileName)
        {
            var dbe        = new DBEngine();
            var tableFound = false;

            if (File.Exists(fileName))
            {
                var dbData = dbe.OpenDatabase(fileName);
                foreach (TableDef td in dbData.TableDefs)
                {
                    if (td.Name == "tblGrid25Inland")
                    {
                        tableFound = true;
                        break;
                    }
                }

                if (!tableFound)
                {
                    tableFound = CreateInlandGridTable(dbData);
                }
            }

            if (!tableFound)
            {
                var dbData = dbe.CreateDatabase(fileName, LanguageConstants.dbLangGeneral);
                tableFound = CreateInlandGridTable(dbData);
            }
            return(tableFound);
        }
コード例 #2
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (status)
            {
                db.Close();
            }
            SaveFileDialog saveFD = new SaveFileDialog();

            saveFD.Title            = "Create a new database";
            saveFD.InitialDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\App_Data";
            saveFD.Filter           = "Database files(*.accdb)|*.accdb";
            saveFD.RestoreDirectory = true;

            if (saveFD.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(saveFD.FileName))
                {
                    File.Delete(saveFD.FileName);
                }

                db             = dbe.CreateDatabase(saveFD.FileName, LanguageConstants.dbLangGeneral);
                labelName.Text = Path.GetFileName(saveFD.FileName);
                displayInfo();
                status = true;
            }
        }
コード例 #3
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            string fileName   = txtFileName.Text + ".accdb";
            string folderpath = txtFolderPath.Text + "/";

            try
            {
                DBEngine dbeng = new DBEngine();
                Database mydb;

                mydb = dbeng.CreateDatabase(folderpath + fileName, DAO.LanguageConstants.dbLangGeneral);

                MessageBox.Show("Data Base file " + fileName + " has been created", "Creation", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();

                wizardTable wiztable = new wizardTable(fileName, mydb, false);
                wiztable.MdiParent = mainForm.ActiveForm;

                wiztable.Show();
            }
            catch
            {
                MessageBox.Show("Data Base " + fileName + " exist\nSelect other filename", "File Exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtFileName.Text = "";
            }
        }
コード例 #4
0
        public override void Init(int flowCount, long flowRecordCount)
        {
            DBEngine dbEng = new DBEngine();

            Microsoft.Office.Interop.Access.Dao.Database db = dbEng.CreateDatabase(String.Format(@"{0}\{1}", DataDirectory, Name), LanguageConstants.dbLangGeneral);
            db.Close();

            connections = new IDbConnection[flowCount];
            commands    = new IDbCommand[flowCount];

            for (int i = 0; i < flowCount; i++)
            {
                IDbConnection connection = new OleDbConnection(ConnectionString);
                connection.Open();
                connections[i] = connection;

                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }

                commands[i] = CreateCommand(connection);
            }
            connections[0].ExecuteNonQuery(CreateTableQuery());
        }
コード例 #5
0
ファイル: frmNew.cs プロジェクト: Sigurrosist/MiniAccess
        private void frmNew_Load(object sender, EventArgs e)
        {
            DBEngine dbe = new DBEngine();

            myDB      = dbe.CreateDatabase(Filepath_new, LanguageConstants.dbLangGeneral);
            this.Name = frmname;
        }
コード例 #6
0
ファイル: Database.cs プロジェクト: Metapyziks/DatabaseTools
            private static void CreateDatabase(String connStrFormat, params String[] args)
            {
#if SQL_SERVER_CE
                var engine = new DBEngine(String.Format(connStrFormat, args));
                engine.CreateDatabase();
                engine.Dispose();
#endif
                Connect(connStrFormat, args);
            }
コード例 #7
0
        private Database CreateDB(string path)
        {
            DBEngine Dbe = new DBEngine();
            Database myDB;

            myDB = Dbe.CreateDatabase(path, DAO.LanguageConstants.dbLangGeneral);
            myDB.Close();
            return(myDB);
        }
コード例 #8
0
        private void metroTile1_Click(object sender, EventArgs e)
        {
            //Checks if the textbox for database name is empty
            if (metroTextBoxDatabaseName.Text == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter the database name in textbox", "Important", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            else if (metroLabelPath.Text == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "Specify a path for database", "Important", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            DBEngine dbe = new DBEngine();

            Database myDB = dbe.CreateDatabase(metroLabelPath.Text + "\\" + metroTextBoxDatabaseName.Text + ".accdb", LanguageConstants.dbLangGeneral);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: benktesh/aggregateaccess
        private static void CleanOutputDb()
        {
            string query = null;
            var    file  = input.CombinedOutputFileName;

            if (File.Exists(file))
            {
                Console.Write($"Cleaning Up Output Db {file}");
                string connetionString = null;
                connetionString = @"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + file;
                OdbcConnection odbcConnection = new OdbcConnection(connetionString);
                try
                {
                    odbcConnection.Open();
                    List <string> tableNames = input.TableNames.ToList();
                    Console.Write(" Deleted ");
                    foreach (var tableName in tableNames)
                    {
                        query = "Delete * From " + tableName + ";";
                        OdbcCommand command = new OdbcCommand(query);
                        command.Connection = odbcConnection;
                        int result = command.ExecuteNonQuery();
                        Console.Write($"{result} {tableName} records...");
                    }
                    Console.Write("\n");
                    odbcConnection.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                //Call compact and repair after cleaning the tables.
                CompactAndRepair(file);
            }
            else
            {
                var engine = new DBEngine();
                var dbs    = engine.CreateDatabase(input.CombinedOutputFileName, ";LANGID=0x0409;CP=1252;COUNTRY=0", DatabaseTypeEnum.dbVersion150);
                dbs.Close();
                dbs = null;
                Console.WriteLine($"Created {input.CombinedOutputFileName}.");
            }
        }
コード例 #10
0
        private void bttnCreatenSaveData_Click(object sender, EventArgs e)
        {
            svflDialog.Filter = "Microsoft Access|.accdb|All Files|*.*";
            //svflDialog.
            if (svflDialog.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(svflDialog.FileName))
                {
                    File.Delete(svflDialog.FileName);
                }

                myDB = dbe.CreateDatabase(svflDialog.FileName, DAO.LanguageConstants.dbLangGeneral);
                Path.GetFullPath(svflDialog.FileName);



                myDB.Close();
            }
            this.Height = 190;
            bttnCreatenSaveData.Enabled = false;
        }
コード例 #11
0
ファイル: frmDatabase.cs プロジェクト: DiogoTM/Mini-Access
        private void tleCreate_Click(object sender, EventArgs e)
        {
            if (lblPath.Text == ".")
            {
                MetroMessageBox.Show(this, "Please select a valid folder and file name!", "Create Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (File.Exists(lblPath.Text))
            {
                File.Delete(lblPath.Text);
            }
            DBEngine dbe  = new DBEngine();
            Database myDB = dbe.CreateDatabase(lblPath.Text, DAO.LanguageConstants.dbLangGeneral);

            MetroMessageBox.Show(this, Path.GetFileNameWithoutExtension(myDB.Name) + " was created with success!", "Create Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
            frmTable ft = new frmTable(myDB);

            ft.MdiParent = this.ParentForm;
            ft.Show();
            this.Close();
        }
コード例 #12
0
        private void btn_create_Click(object sender, EventArgs e)
        {
            try
            {
                // Deleting the existing Database before creating a new one.
                if (File.Exists(saveFileDialog1.FileName))
                {
                    File.Delete(saveFileDialog1.FileName);
                }
            }
            catch (IOException exc)
            {
                MessageBox.Show("This database exists and is already open in another application. Please close it before proceeding.", this.MdiParent.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                clsGlobal.myDB = dbe.CreateDatabase(saveFileDialog1.FileName, DAO.LanguageConstants.dbLangGeneral);
            }
            catch (Exception exc)
            {
                string message = "The following error occurred while creating the database:\n\n";
                message += exc.Message;

                MessageBox.Show(message, this.MdiParent.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                // If there was a database opened the reference to it is lost at this point
                // so database manipulation must be disabled.
                ((frmAccess)this.MdiParent).toggleDatabaseManipulation(false);
                return;
            }

            MessageBox.Show("The database was created successfully!\nYou may now use the menu Database > Create Table to add tables to it.", this.MdiParent.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

            // Enabling database manipulation.
            ((frmAccess)this.MdiParent).toggleDatabaseManipulation(true);

            this.Close();
        }
コード例 #13
0
 private void metroButtonSaveData_Click_1(object sender, EventArgs e)
 {
     if (metroTextBoxName.Text == "")
     {
         MessageBox.Show("You must give a name to your DataBase", "Important Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         saveFileDialog1.Filter   = "Microsoft Access|*.accdb|All Files|*.*";
         saveFileDialog1.FileName = metroTextBoxName.Text;
         if (saveFileDialog1.ShowDialog() == DialogResult.OK)
         {
             if (File.Exists(saveFileDialog1.FileName))
             {
                 File.Delete(saveFileDialog1.FileName);
             }
             myDB = dbe.CreateDatabase(saveFileDialog1.FileName, DAO.LanguageConstants.dbLangGeneral);
             Path.GetFullPath(saveFileDialog1.FileName);
             metroButtonCreateFake.Show();
         }
     }
 }
コード例 #14
0
        Database myDB; //---- create database object
        //TableDef myTb; //-----table object

        private void frmNewDB_Load(object sender, EventArgs e)
        {
            this.Text = "New DataBase: " + Variables.NewFilePath;
            //First things first - lets create a new file!
            dbE = new DBEngine();
            try //------------------------------ create database object as myDB:
            {
                myDB = dbE.CreateDatabase(Variables.NewFilePath, DAO.LanguageConstants.dbLangGeneral);
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Error Creating new Database!!! \n" +
                //    "File path: " + newMDBPath  +"\n" + ex,
                //                "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorMsgDB(ex.ToString());
                this.Close();
            }
            //creating columnd for a grid view to display tables fields:
            gridTblFld.Columns.Add("Names", "Name");
            gridTblFld.Columns.Add("ColNames", "Type");
            gridTblFld.Columns.Add("ColLength", "Length");
            gridTblFld.Rows.Clear();
        }
コード例 #15
0
 private void frmNewDB_Load(object sender, EventArgs e)
 {
     myDB = dbe.CreateDatabase(txtSavedPath.Text + "\\" + txtFileName.Text, DAO.LanguageConstants.dbLangGeneral);
 }
コード例 #16
0
        public override void Init(int flowCount, long flowRecordCount)
        {
            DBEngine dbEng = new DBEngine();
            Microsoft.Office.Interop.Access.Dao.Database db = dbEng.CreateDatabase(String.Format(@"{0}\{1}", DataDirectory, Name), LanguageConstants.dbLangGeneral);
            db.Close();

            connections = new IDbConnection[flowCount];
            commands = new IDbCommand[flowCount];

            for (int i = 0; i < flowCount; i++)
            {
                IDbConnection connection = new OleDbConnection(ConnectionString);
                connection.Open();
                connections[i] = connection;

                if (connection.State == ConnectionState.Closed)
                    connection.Open();

                commands[i] = CreateCommand(connection);
            }
            connections[0].ExecuteNonQuery(CreateTableQuery());
        }