private void ingresar_Click(object sender, EventArgs e)
        {
            string ids    = "";
            string values = "";

            for (int i = 0; i < id.Count; i++)
            {
                if (i < (id.Count - 1))
                {
                    ids    += id [i].Text + ",";
                    values += "'" + id_caja [i].Text + "',";
                }
                else
                {
                    ids    += id [i].Text;
                    values += "'" + id_caja [i].Text + "'";
                }
            }
            string query = "INSERT INTO " + arbol_conexiones.SelectedNode.Text + " (" + ids + ") VALUES (" + values + ");";

            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol_conexiones.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(query, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Registro insertado correctamente");
            } catch (DB2Exception ex) {
                MessageBox.Show("Ha ocurrido un error al insertar\n" + ex.Message);
            }
            connection.Close();
        }
        private void ModificarPrimaryKey_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"select tab.tabname from syscat.tables tab inner join syscat.tabconst const  on const.tabschema = tab.tabschema  and const.tabname = tab.tabname and const.type = 'P' join syscat.keycoluse key  on const.tabschema = key.tabschema  and const.tabname = key.tabname  and const.constname = '" + arbol.SelectedNode.Text + "' where tab.type = 'T'  and tab.tabschema like 'DB2ADMIN' group by tab.tabschema, const.constname, tab.tabname  order by tab.tabschema, const.constname;", connection);
                DB2DataReader buffer = cmd.ExecuteReader();

                while (buffer.Read())
                {
                    var nombre_tabla = buffer ["TABNAME"].ToString();
                    buffer.Close();
                    richTextBox1.Text = "ALTER TABLE " + nombre_tabla + " DROP PRIMARY KEY;";

                    break;
                }
            } catch (DB2Exception ex) {
                MessageBox.Show("Error \n" + ex.Message);
            }
            connection.Close();
            TreeNodeCollection cl = arbol.SelectedNode.Parent.Parent.Parent.Nodes [0].Nodes;

            foreach (TreeNode tabla in cl)
            {
                comboBox1.Items.Add(tabla.Text);
            }
        }
Пример #3
0
        private void button3_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                if (checkBox2.Checked)
                {
                    DB2Command cmd = new DB2Command("ALTER TABLE " + arbol.SelectedNode.Text + " ALTER COLUMN " + nombre_campo + " DROP NOT NULL;", connection);

                    cmd.ExecuteNonQuery();
                }
                else
                {
                    DB2Command cmd = new DB2Command("ALTER TABLE " + arbol.SelectedNode.Text + " ALTER COLUMN " + nombre_campo + " SET NOT NULL;", connection);

                    cmd.ExecuteNonQuery();
                }
                MessageBox.Show("Campo modificado");
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al modificar\n" + ex.Message);
            }
            connection.Close();
        }
Пример #4
0
        private void caja_SelectedIndexChanged(object sender, EventArgs e)
        {
            data_set.Rows.Clear();
            Expresion.Items.Clear();

            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Text);

            try {
                connection.Open();
                int           posicion     = caja.SelectedIndex;
                string        nombre_tabla = caja.Items [posicion].ToString();
                DB2Command    cmd          = new DB2Command(@"SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = '" + nombre_tabla + "';", connection);
                DB2DataReader buffer       = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var nombre_campo = buffer ["NAME"].ToString();
                    Expresion.Items.Add(nombre_campo);
                }
                buffer.Close();
            } catch (DB2Exception ex) {
                MessageBox.Show("Ha ocurrido un error\n" + ex.Message);
            }
            connection.Close();
        }
Пример #5
0
        private void ModificarForeignKey_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Parent.Text); try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"select  tabname from syscat.references where  constname = '" + arbol.SelectedNode.Text + "';", connection);
                DB2DataReader buffer = cmd.ExecuteReader();

                while (buffer.Read())
                {
                    var nombre_tabla = buffer ["TABNAME"].ToString();
                    buffer.Close();
                    richTextBox1.Text = "ALTER TABLE " + nombre_tabla + " DROP FOREIGN KEY " + arbol.SelectedNode.Text + ";";
                    break;
                }
            } catch (DB2Exception ex) {
                MessageBox.Show("Error\n" + ex.Message);
            }
            connection.Close();
            TreeNodeCollection cl = arbol.SelectedNode.Parent.Parent.Parent.Nodes [0].Nodes;

            foreach (TreeNode tabla in cl)
            {
                comboBox1.Items.Add(tabla.Text);
            }
        }
Пример #6
0
        private void ModificarVista_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"select NAME, TEXT from SYSIBM.SYSVIEWS WHERE CREATOR='DB2ADMIN' and NAME='" + arbol.SelectedNode.Text + "';", connection);
                DB2DataReader buffer = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var function = buffer ["TEXT"].ToString().ToUpper();
                    valor = buffer ["NAME"].ToString();
                    int pl = function.IndexOf("SELECT");
                    function          = function.Substring(pl);
                    richTextBox1.Text = function;
                    textBox1.Text     = valor;
                    break;
                }
                buffer.Close();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al mostrar Vista\n" + ex.Message);
            }
            connection.Close();
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(richTextBox1.Text, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Ejecutado correctamente");
            } catch (DB2Exception ex) {
                MessageBox.Show("Ha ocurrido un error\n" + ex.Message);
            }
            connection.Close();
        }
Пример #8
0
        public void comprobarSintaxis()
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(richTextBox1.Text, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("No se ha encontrado ningun error en SQL");
            } catch (DB2Exception ex) {
                MessageBox.Show("Revise la sintaxis\n" + ex.Message);
            }
            connection.Close();
        }
Пример #9
0
        private void Crear_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(richTextBox1.Text, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Check creado correctamente");
                this.Hide();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al crear check\n" + ex.Message);
            } catch (Exception ex2) { }
            connection.Close();
        }
Пример #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(richTextBox1.Text, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Modificacion correcta!");
                this.Hide();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al modificar Trigger\n" + ex.Message);
            } catch (Exception ex2) { }
            connection.Close();
        }
Пример #11
0
        private void button2_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command("RENAME TABLE " + nombre_Tabla + " TO " + textBox1.Text + ";", connection);
                cmd.ExecuteNonQuery();
                nombre_Tabla = textBox1.Text;
                MessageBox.Show("Tabla modificada correctamente");
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al modificar tabla\n" + ex.Message);
            }
            connection.Close();
        }
Пример #12
0
        private void MostrarDatosTabla_Load(object sender, EventArgs e)
        {
            try {
                tabla_name.Text = "DATOS DE TABLA : " + arbol_conexiones.SelectedNode.Text;
                PantallaPrincipal pn         = new PantallaPrincipal();
                DB2Connection     connection = pn.obtenerConexion(arbol_conexiones.SelectedNode.Parent.Parent.Text);

                connection.Open();
                DB2Command cmd = new DB2Command(@"SELECT * FROM " + arbol_conexiones.SelectedNode.Text + "; ", connection);
                adapter = new DB2DataAdapter(cmd);
                ds      = new DataTable();
                adapter.Fill(ds);
                data_tablas.DataSource = ds;
                connection.Close();
            } catch (DB2Exception ex) { } catch { }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(richTextBox1.Text, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Procedimiento creado satisfactoriamente!");
                this.Hide();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al crear procedimiento\n" + ex.Message);
            }
            connection.Close();
        }
Пример #14
0
        private void button3_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command("ALTER TABLE " + nombre_Tabla + " DROP COLUMN " + data_tablas.CurrentRow.Cells["NAME"].Value.ToString() + ";", connection);
                cmd.ExecuteNonQuery();
                nombre_Tabla = textBox1.Text;
                data_tablas.Rows.Remove(data_tablas.CurrentRow);
                MessageBox.Show("Campo Borradp correctamente");
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al borrar campo\n" + ex.Message);
            }
            connection.Close();
        }
Пример #15
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (nombre_campo != nombre.Text)
     {
         PantallaPrincipal pn         = new PantallaPrincipal();
         DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);
         try {
             connection.Open();
             DB2Command cmd = new DB2Command("ALTER TABLE " + arbol.SelectedNode.Text + " RENAME COLUMN " + nombre_campo + " TO " + nombre.Text + ";", connection);
             cmd.ExecuteNonQuery();
             MessageBox.Show("Campo modificado");
         } catch (DB2Exception ex) {
             MessageBox.Show("Error al modificar\n" + ex.Message);
         }
         connection.Close();
         nombre_campo = nombre.Text;
     }
 }
Пример #16
0
        private void ModificarTabla_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command     cmd   = new DB2Command("SELECT NAME, COLTYPE, LENGTH, SCALE, NULLS FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = '" + arbol.SelectedNode.Text + "';", connection);
                DB2DataAdapter data  = new DB2DataAdapter(cmd);
                DataTable      tabla = new DataTable();
                data.Fill(tabla);
                data_tablas.DataSource = tabla;
                textBox1.Text          = arbol.SelectedNode.Text;
                nombre_Tabla           = textBox1.Text;
            } catch (DB2Exception ex) {
            }
            connection.Close();
        }
Пример #17
0
        public void ingresar2(string q)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol_conexiones.SelectedNode.Parent.Parent.Text);

            try
            {
                connection.Open();
                DB2Command cmd = new DB2Command(q, connection);
                cmd.ExecuteNonQuery();
                //MessageBox.Show("Registro insertado correctamente");
            }
            catch (DB2Exception ex)
            {
                //MessageBox.Show("Ha ocurrido un error al insertar\n" + ex.Message);
            }
            connection.Close();
        }
Пример #18
0
        private void ModificarCampos_Load_1(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command("select NAME from SYSIBM.SYSCOLUMNS where tbname = '" + arbol.SelectedNode.Text + "' AND NAME ='" + data_tablas.Cells ["NAME"].Value.ToString() + "' and keyseq > 0 order by keyseq", connection);
                DB2DataReader buffer = cmd.ExecuteReader();
                if (buffer.Read())
                {
                    checkBox1.Checked = true;
                }
                buffer.Close();
            } catch (DB2Exception ex) {
            }
            connection.Close();
        }
Пример #19
0
        //hace un truncate de la tabla, elimina todos los valores que se quiera
        public void LimpiarTabla_SinMensaje()
        {
            PantallaPrincipal pn1 = new PantallaPrincipal();

            using (DB2Connection connection = pn1.obtenerConexion(arbol_conexiones.SelectedNode.Parent.Parent.Text))
            {
                try
                {
                    connection.Open();
                    DB2Command cmd = new DB2Command("TRUNCATE TABLE " + arbol_conexiones.SelectedNode.Text + " IMMEDIATE;", connection);
                    cmd.ExecuteNonQuery();
                }
                catch (DB2Exception ex)
                {
                    MessageBox.Show("Ha ocurrido un error al limpiar tabla\n" + ex.Message);
                }
                connection.Close();
            }
        }
Пример #20
0
        private void MostrarProcedimiento_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command("SELECT ROUTINE_DEFINITION FROM SYSIBM.ROUTINES WHERE SPECIFIC_SCHEMA = 'DB2ADMIN' AND ROUTINE_NAME ='" + arbol.SelectedNode.Text.ToUpper() + "';", connection);
                DB2DataReader buffer = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var texto = buffer ["ROUTINE_DEFINITION"].ToString();
                    richTextBox1.Text = texto;
                }
                buffer.Close();
            } catch (DB2Exception ex) {
            }
            connection.Close();
        }
Пример #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            string expresiones = obtenerQuery();
            string query       = "";
            int    posicion    = caja.SelectedIndex;
            int    posicion2   = caja2.SelectedIndex;

            if (posicion == -1 || posicion2 == -1)
            {
                MessageBox.Show("Te falta seleccionar correctamente el tipo de indice\n");
                return;
            }
            string nombre_tabla = caja.Items [posicion].ToString();
            string tipo_indice  = caja2.Items [posicion2].ToString();

            if (tipo_indice == "NO UNICO")
            {
                query = "CREATE INDEX " + nombre_indice.Text + " ON " + nombre_tabla + " " + expresiones + ";";
            }
            else
            {
                query = "CREATE UNIQUE INDEX " + nombre_indice.Text + " ON " + nombre_tabla + " " + expresiones + ";";
            }
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Text);

            try {
                connection.Open();
                DB2Command cmd = new DB2Command(query, connection);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Indice creado correctamente");
                TreeNode nodo = arbol.SelectedNode.Nodes.Add(nombre_indice.Text);
                nodo.ImageIndex         = 3;
                nodo.SelectedImageIndex = 3;
                nodo.ContextMenuStrip   = subMenus [4];
                connection.Close();
                this.Hide();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al crear el indice\n" + ex.Message);
            }
            connection.Close();
        }
Пример #22
0
        private void ModificarTrigger_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"SELECT TEXT FROM SYSCAT.TRIGGERS WHERE TRIGSCHEMA ='DB2ADMIN' AND TRIGNAME= '" + arbol.SelectedNode.Text + "';", connection);//OBTENER TABLAS DE LA BASE DE DATOS
                DB2DataReader buffer = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var function = buffer ["TEXT"].ToString();
                    richTextBox1.Text = function;
                    break;
                }
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al mostrar Vista\n" + ex.Message);
            } catch (Exception ex2) { }
            connection.Close();
        }
Пример #23
0
        private void MostrarTriggers_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd = new DB2Command(@"SELECT TEXT FROM SYSCAT.TRIGGERS WHERE TRIGSCHEMA ='DB2ADMIN' AND TRIGNAME= '" + arbol.SelectedNode.Text + "';", connection);//OBTENER TABLAS DE LA BASE DE DATOS
                DB2DataReader bff = cmd.ExecuteReader();
                while (bff.Read())
                {
                    var Names = bff ["TEXT"].ToString();
                    richTextBox1.Text = Names;
                    break;
                }
                bff.Close();
            } catch (DB2Exception ex) {
            }
            connection.Close();
        }
Пример #24
0
        public string obtenerTabla()
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"SELECT TBNAME FROM SYSIBM.SYSCHECKS WHERE TBCREATOR='DB2ADMIN' AND NAME ='" + arbol.SelectedNode.Text + "';", connection);
                DB2DataReader buffer = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var function = buffer ["TBNAME"].ToString();
                    return(function);
                }
            } catch (DB2Exception ex) {
                MessageBox.Show("Error \n" + ex.Message);
            }
            connection.Close();
            return("");
        }
Пример #25
0
        private void MostrarCheck_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"SELECT TEXT FROM SYSIBM.SYSCHECKS WHERE TBCREATOR='DB2ADMIN' AND NAME ='" + arbol.SelectedNode.Text + "';", connection);
                DB2DataReader buffer = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var function = buffer ["TEXT"].ToString();
                    richTextBox1.Text = function;
                    break;
                }
                buffer.Close();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al mostrar Check\n" + ex.Message);
            }
            connection.Close();
        }
Пример #26
0
        private void ModificarFuncion_Load(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                DB2Command    cmd    = new DB2Command(@"select text from syscat.routines where routineschema not like 'SYS%'and routineschema='DB2ADMIN' and text not like '%PROCEDURE%' and ROUTINENAME ='" + arbol.SelectedNode.Text + "';", connection);
                DB2DataReader buffer = cmd.ExecuteReader();
                while (buffer.Read())
                {
                    var function = buffer ["TEXT"].ToString();
                    richTextBox1.Text = function;
                    break;
                }
                buffer.Close();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al mostrar funcion\n" + ex.Message);
            }
            connection.Close();
        }
Пример #27
0
        private void button5_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                string query = "ALTER TABLE " + tabla + " ADD COLUMN " + nombre.Text + " ";
                string nullo = "";
                if (checkBox2.Checked)
                {
                    nullo += "NULL";
                }
                else
                {
                    nullo += "NOT NULL DEFAULT";
                }
                if (dato.Text == "VARCHAR")
                {
                    query += dato.Text + "(" + tamano.Text + ") " + nullo;
                }
                if (dato.Text == "INT")
                {
                    query += dato.Text + " " + nullo;
                }
                if (dato.Text.Equals("DECIMAL") || dato.Text.Equals("NUMERIC"))
                {
                    query += dato.Text + "(" + tamano.Text + "," + escala.Text + ") " + nullo;
                }

                DB2Command cmd = new DB2Command(query, connection);
                cmd.ExecuteNonQuery();

                MessageBox.Show("Campo Anadido correctamente");
                this.Hide();
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al borrar campo\n" + ex.Message);
            }
            connection.Close();
        }
Пример #28
0
        private void button5_Click(object sender, EventArgs e)
        {
            PantallaPrincipal pn         = new PantallaPrincipal();
            DB2Connection     connection = pn.obtenerConexion(arbol.SelectedNode.Parent.Parent.Text);

            try {
                connection.Open();
                if (escala.Enabled)
                {
                    DB2Command cmd = new DB2Command("ALTER TABLE " + arbol.SelectedNode.Text + " ALTER COLUMN " + nombre_campo + " SET DATA TYPE " + dato.SelectedItem.ToString() + " (" + tamano.Text + "," + escala.Text + ");", connection);
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    DB2Command cmd = new DB2Command("ALTER TABLE " + arbol.SelectedNode.Text + " ALTER COLUMN " + nombre_campo + " SET DATA TYPE " + dato.SelectedItem.ToString() + " (" + tamano.Text + ");", connection);
                    cmd.ExecuteNonQuery();
                }
                MessageBox.Show("Campo modificado");
            } catch (DB2Exception ex) {
                MessageBox.Show("Error al modificar\n" + ex.Message);
            }
            connection.Close();
        }
Пример #29
0
        private void LlenarTabla_Load(object sender, EventArgs e)
        {
            //Sacar los ids

            DataTable         tabla1 = new DataTable();
            PantallaPrincipal pn1    = new PantallaPrincipal();

            using (DB2Connection connection = pn1.obtenerConexion(arbol_conexiones.SelectedNode.Parent.Parent.Text))
            {
                try
                {
                    connection.Open();
                    DB2Command     cmd  = new DB2Command("SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = '" + arbol_conexiones.SelectedNode.Text + "';", connection);
                    DB2DataAdapter data = new DB2DataAdapter(cmd);

                    data.Fill(tabla1);
                    dataGridView2.DataSource = tabla1;
                }
                catch (DB2Exception ex)
                { }
                connection.Close();
            }


            // Agregando valores a la lista de los IDS
            foreach (DataRow row in tabla1.Rows)
            {
                foreach (DataColumn column in tabla1.Columns)
                {
                    string name = (row[column]).ToString();
                    id.Add(name);
                }
            }

            //Sacar tipo de dato
            DataTable         tabla = new DataTable();
            PantallaPrincipal pn    = new PantallaPrincipal();

            using (DB2Connection connection = pn.obtenerConexion(arbol_conexiones.SelectedNode.Parent.Parent.Text))
            {
                try
                {
                    connection.Open();
                    DB2Command     cmd  = new DB2Command("SELECT COLTYPE FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = '" + arbol_conexiones.SelectedNode.Text + "';", connection);
                    DB2DataAdapter data = new DB2DataAdapter(cmd);

                    data.Fill(tabla);
                    dataGridView1.DataSource = tabla;
                }
                catch (DB2Exception ex)
                {}
                connection.Close();
            }

            // Agregando tipos de datos a la lista
            foreach (DataRow row in tabla.Rows)
            {
                foreach (DataColumn column in tabla.Columns)
                {
                    string tipo = (row[column]).ToString();
                    tipoDato.Add(tipo);
                }
            }
        }