Documentos de Académico
Documentos de Profesional
Documentos de Cultura
1 public Form1()
2 {
3 InitializeComponent();
4 actual = getFirstId();
5 showData();
6 }
1 this.oleDbDataAdapter1.SelectCommand.CommandText = query;
2 this.oleDbConnection1.Open();
3 this.oleDbDataAdapter1.SelectCommand.Connection = oleDbConnection1;
4
5 OleDbDataReader reader = this.oleDbDataAdapter1.SelectCommand.ExecuteReader();
6 while(reader.Read()){
7 textBox1.Text = reader["Nombre"].ToString();
8 textBox2.Text = reader["Direccion"].ToString();
9 textBox3.Text = reader["Telefono"].ToString();
10 textBox4.Text = reader["Nota"].ToString();
11 }
12
13 this.oleDbConnection1.Close();
1 try
2 {
3 this.oleDbDataAdapter1.InsertCommand.CommandText = query;
4 this.oleDbConnection1.Open();
5 this.oleDbDataAdapter1.InsertCommand.Connection = oleDbConnection1;
6
7 this.oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
8
9 this.oleDbConnection1.Close();
10
11 MessageBox.Show("Registro agregado exitosamente");
12
13 this.textBox1.Text = "";
14 this.textBox2.Text = "";
15 this.textBox3.Text = "";
16 this.textBox4.Text = "";
17
18 actual = getFirstId();
19 showData();
20 }
21 catch (System.Data.OleDb.OleDbException exp)
22 {
23 this.oleDbConnection1.Close();
24
25 MessageBox.Show(exp.ToString());
26 }
donde la variable query contiene la cadena de texto con la
instrucción insert.
CODIGO DEL BOTON ACTUALIZAR REGISTRO
1 try
2 {
3 this.oleDbDataAdapter1.UpdateCommand.CommandText = query;
4
5 this.oleDbConnection1.Open();
6
7 this.oleDbDataAdapter1.UpdateCommand.Connection = oleDbConnection1;
8
9 this.oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery();
10
11 this.oleDbConnection1.Close();
12
13 MessageBox.Show("Registro actualizado correctamente.");
14
15 this.textBox1.Text = "";
16 this.textBox2.Text = "";
17 this.textBox3.Text = "";
18 this.textBox4.Text = "";
19
20 actual = getFirstId();
21 showData();
22 }
23 catch (System.Data.OleDb.OleDbException exp)
24 {
25 this.oleDbConnection1.Close();
26 MessageBox.Show(exp.ToString());
27 }
CODIGO DEL BOTON BORRAR REGISTRO
1 try
2 {
3 this.oleDbDataAdapter1.DeleteCommand.CommandText =query;
4 this.oleDbConnection1.Open();
5
6 this.oleDbDataAdapter1.DeleteCommand.Connection = oleDbConnection1;
7
8 this.oleDbDataAdapter1.DeleteCommand.ExecuteNonQuery();
9
10 this.oleDbConnection1.Close();
11
12 MessageBox.Show("Registro eliminado correctamente");
13
14 this.textBox1.Text = "";
15 this.textBox2.Text = "";
16 this.textBox3.Text = "";
17 this.textBox4.Text = "";
18
19 actual = getFirstId();
20 showData();
21 }
22 catch (System.Data.OleDb.OleDbException exp)
23 {
24 this.oleDbConnection1.Close();
25 MessageBox.Show(exp.ToString());
26 }
Una vez mas el código de la variable query es la
instrucción DELETE para eliminar el registro que
corresponda a ese Nombre.
CODIGO DEL BOTON BUSCAR REGISTRO
https://www.youtube.com/watch?time_continue=8&v=fa5Hy_BGeKI&feature=emb_logo