private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { // al darle doble clic a cualquier celda, se llevarán los datos del datagrid al siguiente formulario Enfermedades enfe = new Enfermedades(); enfe.MdiParent = this.MdiParent; int cod1; string columna = dataGridView1.CurrentCell.RowIndex.ToString();//selecciona numero de columna int columna_id = Convert.ToInt32(columna); string dato1 = dataGridView1.Rows[columna_id].Cells[0].Value.ToString(); int datoint = Convert.ToInt32(dato1); //MessageBox.Show(datoint.ToString()); string MyConnection3 = "Driver ={ MySQL ODBC 3.51 Driver }; Dsn=servidor_seguridad; UID=root; PWD = ; "; string Query = "select descrip_enfer,id_enfermedad from enfermedades where id_enfermedad =" + datoint + ";"; OdbcConnection MyConn2 = new OdbcConnection(MyConnection3); OdbcCommand MyCommand2 = new OdbcCommand(Query, MyConn2); MyConn2.Open(); OdbcDataReader reader = MyCommand2.ExecuteReader(); // coloca en los textBox, y comboBox correspondientes la informacion que se obtiene de la base de datos if (reader.Read()) { enfe.descripcion.Text = (string)reader["descrip_enfer"]; cod1 = (int)reader["id_enfermedad"]; enfe.primarykey.Text = cod1.ToString(); } reader.Close(); MyConn2.Close(); enfe.Show(); }
private void button2_Click(object sender, EventArgs e) { // al presionar el boton guardar lo que hará es verificar el ultimo codigo ingresado y // y sumarle 1, para que en el siguiente formulario aparezca ya el codigo que sigue Enfermedades enfe = new Enfermedades(); enfe.MdiParent = this.MdiParent; int cod1; string MyConnection3 = "Driver ={ MySQL ODBC 3.51 Driver }; Dsn=servidor_seguridad; UID=root; PWD = ; "; string Query2 = "Select id_enfermedad from enfermedades order by id_enfermedad DESC LIMIT 1;"; OdbcConnection MyConn3 = new OdbcConnection(MyConnection3); OdbcCommand MyCommand3 = new OdbcCommand(Query2, MyConn3); MyConn3.Open(); OdbcDataReader myreader3; myreader3 = MyCommand3.ExecuteReader(); if (myreader3.Read()) { cod1 = (int)myreader3["id_enfermedad"]; int cod2 = cod1 + 1; enfe.primarykey.Text = cod2.ToString(); enfe.primarykey.Visible = true; } enfe.Show(); }