Beispiel #1
0
        public void createDatabase( )
        {
            frmCreate frmCreateDataBase = new frmCreate();

            frmCreateDataBase.Text           = "Create database";
            frmCreateDataBase.lblNombre.Text = "Database name:";
            frmCreateDataBase.ShowDialog();

            if (frmCreateDataBase.DialogResult == DialogResult.OK)
            {
                string databaseName = frmCreateDataBase.txtNombreDatabase.Text;
                string query        = "CREATE DATABASE " + databaseName + ";";
                ShowLog("Query: " + query);
                try
                {
                    mySqlCommand = new MySqlCommand(query, mySqlConnection);
                    mySqlCommand.ExecuteNonQuery();
                    PutDataInTreeView();
                }
                catch (Exception e)
                {
                    DialogResult dialog = MessageBox.Show("ERROR to extract data: " + e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        public void createTable()
        {
            frmCreate frmCreateDataBase = new frmCreate();

            frmCreateDataBase.Text           = "Create table";
            frmCreateDataBase.lblNombre.Text = "Table name:";
            frmCreateDataBase.ShowDialog();

            if (frmCreateDataBase.DialogResult == DialogResult.OK)
            {
                string tableName       = frmCreateDataBase.txtNombreDatabase.Text;
                string query           = "CREATE TABLE " + tableName + "(";
                bool   addedFirstField = false;

                frmFields frmFields = new frmFields();
                frmFields.ShowDialog();

                if (frmFields.DialogResult == DialogResult.OK)
                {
                    int size  = frmFields.fields.Count;
                    int count = 1;
                    foreach (string item in frmFields.fields)
                    {
                        if (count == size)
                        {
                            query += item + " )";
                        }
                        else
                        {
                            query += item + ",";
                        }
                        count += 1;
                    }
                    try
                    {
                        query = query + ";";
                        if (ConfirmQuery(query) == true)
                        {
                            mySqlCommand = new MySqlCommand(query, mySqlConnection);
                            mySqlCommand.ExecuteNonQuery();
                            PutDataInTreeView();
                            ShowLog("Query: " + query);
                        }
                    }
                    catch (Exception e)
                    {
                        DialogResult dialog = MessageBox.Show("ERROR to extract data: " + e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }