Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views4 pages

Using MySql - dat-WPS Office

The document is a C# Windows Forms application for managing student data using MySQL. It includes functionalities to add, delete, and display students in a database. The application connects to a MySQL database and executes SQL commands based on user interactions with the UI buttons.

Uploaded by

katexauce336
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Using MySql - dat-WPS Office

The document is a C# Windows Forms application for managing student data using MySQL. It includes functionalities to add, delete, and display students in a database. The application connects to a MySQL database and executes SQL commands based on user interactions with the UI buttons.

Uploaded by

katexauce336
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

using MySql.Data.

MySqlClient;

using System;

using System.Data;

using System.Windows.Forms;

namespace GestionEtudiants

public partial class Form1 : Form

private string connectionString = "server=localhost;database=bddetudiant;uid=root;pwd=;";

public Form1()

InitializeComponent();

private void btnAjouter_Click(object sender, EventArgs e)

AjouterEtudiant(txtNom.Text, txtPostnom.Text, txtPrenom.Text, txtPromotion.Text,


int.Parse(txtAnneeInscription.Text));

private void btnSupprimer_Click(object sender, EventArgs e)

SupprimerEtudiant(txtNom.Text);

}
private void btnAfficher_Click(object sender, EventArgs e)

AfficherEtudiants();

private void AjouterEtudiant(string nom, string postnom, string prenom, string promotion, int
anneeinscription)

using (MySqlConnection conn = new MySqlConnection(connectionString))

conn.Open();

string query = "INSERT INTO Etudiant (nom, postnom, prenom, promotion, anneeinscription)
VALUES (@nom, @postnom, @prenom, @promotion, @anneeinscription)";

MySqlCommand cmd = new MySqlCommand(query, conn);

cmd.Parameters.AddWithValue("@nom", nom);

cmd.Parameters.AddWithValue("@postnom", postnom);

cmd.Parameters.AddWithValue("@prenom", prenom);

cmd.Parameters.AddWithValue("@promotion", promotion);

cmd.Parameters.AddWithValue("@anneeinscription", anneeinscription);

cmd.ExecuteNonQuery();

MessageBox.Show("Étudiant ajouté avec succès !");

private void SupprimerEtudiant(string nom)


{

using (MySqlConnection conn = new MySqlConnection(connectionString))

conn.Open();

string query = "DELETE FROM Etudiant WHERE nom = @nom";

MySqlCommand cmd = new MySqlCommand(query, conn);

cmd.Parameters.AddWithValue("@nom", nom);

cmd.ExecuteNonQuery();

MessageBox.Show("Étudiant supprimé avec succès !");

private void AfficherEtudiants()

using (MySqlConnection conn = new MySqlConnection(connectionString))

conn.Open();

string query = "SELECT * FROM Etudiant";

MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);

DataTable dt = new DataTable();

adapter.Fill(dt);

dataGridView1.DataSource = dt;

}
}

You might also like