Repository navigation
Expand file tree
/
Copy pathFormCRUD_Marca.cs
More file actions
71 lines (64 loc) · 2.47 KB
/
Copy pathFormCRUD_Marca.cs
File metadata and controls
71 lines (64 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WinFormsProyectoFinal2021
{
public partial class FormCRUD_Marca : Form
{
public FormCRUD_Marca()
{
InitializeComponent();
}
MySqlConnection conexion = new MySqlConnection("Server=localhost; Database=BDProyectoFinal2021; Uid=root; pwd=;");
private void BtnSeleccionar_Click(object sender, EventArgs e)
{
MySqlCommand comand = new MySqlCommand("select * from Marca", conexion);
MySqlDataAdapter adaptador = new MySqlDataAdapter();
adaptador.SelectCommand = comand;
DataTable tabla = new DataTable();
adaptador.Fill(tabla);
PanelManipulacion.DataSource = tabla;
}
private void BtnSalir_Click(object sender, EventArgs e)
{
Close();
}
private void BtnInsertar_Click(object sender, EventArgs e)
{
conexion.Open();
string Query = "INSERT INTO Marca (id_Marca, Nom_Marca) values ('" + InputId.Text + "', '" + InputNombre.Text + "');";
MySqlCommand comando = new MySqlCommand(Query, conexion);
comando.ExecuteNonQuery();
conexion.Close();
MessageBox.Show($"Se agrego el nuevo registro {InputNombre.Text}");
}
private void BtnActualizar_Click(object sender, EventArgs e)
{
conexion.Open();
string Query = "UPDATE Marca SET id_Marca='" + InputId.Text +
"',Nom_Marca='" + InputNombre.Text +
"'WHERE id_Marca='" + InputId.Text +
"';";
MySqlCommand comando = new MySqlCommand(Query, conexion);
comando.ExecuteNonQuery();
conexion.Close();
MessageBox.Show($"Se agrego el nuevo registro {InputNombre.Text}");
}
private void BtnEliminar_Click(object sender, EventArgs e)
{
conexion.Open();
string Query = "DELETE FROM Marca WHERE id_Marca='" + InputId.Text + "';";
MySqlCommand comando = new MySqlCommand(Query, conexion);
comando.ExecuteNonQuery();
conexion.Close();
MessageBox.Show($"El registro {InputId.Text} ha sido eliminado");
}
}
}