Professional Documents
Culture Documents
C# Ado - Net Mode Connecté
C# Ado - Net Mode Connecté
using System;
using System.Data.SqlClient;
using System.Windows.Forms;
// Afficher
// Remplisage de comboBox
// Get ID
// Ajouter
con.Open();
cmd = new SqlCommand("select * from ...(Nom de table)", con);
dr = cmd.ExecuteReader();
bs.DataSource = dr;
dataGridView1.DataSource = bs;
dr.Close();
con.Close();
MessageBox.Show("Bien Ajouter");
// Modifier
con.Open();
SqlCommand cmd = new SqlCommand("update ...(Nom de table) set ...(exemple nom) = '"
+ textBox1.Text + "' , ...(exemple prenom) = '" + textBox2.Text + "' where ...(id de
table) = '" + comboBox1.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Bien Modifier");
// Supprimer
con.Open();
cmd = new SqlCommand("delete from ...(nom de table) where ...(id de table) ='" +
textBox1.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
// Rechercher
con.Open();
cmd = new SqlCommand("select * from (nom de table) where ...(id de table) ='" +
textBox1.Text + "'", con);
dr = cmd.ExecuteReader();
bs.DataSource = dr;
dataGridView1.DataSource = bs;
dr.Close();
con.Close();
// Vider
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
...
// Form Load
Afficher();
navigation();
RemplirComboBox();
// Exist
// Navigation
// button Premier
bs.MoveFirst();
indexLabel.Text = (bs.Position + 1).ToString();
totalLabel.Text = bs.Count.ToString();
// button Précédent
bs.MovePrevious();
indexLabel.Text = (bs.Position + 1).ToString();
totalLabel.Text = bs.Count.ToString();
// button Suivant
bs.MoveNext();
indexLabel.Text = (bs.Position + 1).ToString();
totalLabel.Text = bs.Count.ToString();
// button Dernier
bs.MoveLast();
indexLabel.Text = (bs.Position + 1).ToString();
totalLabel.Text = bs.Count.ToString();