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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| 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.Data.OleDb;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\TPH\1.accdb");
DataTable dt = new DataTable();
OleDbCommand cmd = new OleDbCommand();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "insert into tph (num,nom,prenom) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
cmd.ExecuteNonQuery();
con.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
MessageBox.Show(" Numeor inserer ");
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "update tph set nom='" + textBox2.Text + "' , prenom ='" + textBox3.Text + "' where num='" + textBox1.Text + "'";
cmd.ExecuteNonQuery();
MessageBox.Show(" Le Numéro a été bien mis à jour ");
con.Close();
}
private void button3_Click(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "delete * from tph where num='" + textBox1.Text + "' and nom='" + textBox2.Text + "' and prenom ='" + textBox3.Text + "'";
cmd.ExecuteNonQuery();
MessageBox.Show(" Numeor Effacé ");
con.Close();
}
private void button4_Click(object sender, EventArgs e)
{
string query = "SELECT * FROM TPH WHERE 1=1";
if (textBox1.Text == string.Empty & textBox2.Text == string.Empty & textBox3.Text == string.Empty)
{
MessageBox.Show("Veuiller saisir un Critère de recherche....!");
}
else
{
if (textBox1.Text.Length > 0)
{
query = query + "and NUM LIKE '" + textBox1.Text + "%'";
}
if (textBox2.Text.Length > 0)
{
query = query + "and [NOM] LIKE '" + textBox2.Text + "%'";
}
if (textBox3.Text.Length > 0)
{
query = query + "and [PRENOM] LIKE '" + textBox3.Text + "%'";
}
OleDbDataAdapter sda = new OleDbDataAdapter(query, con);
sda.Fill(dt);
dataGridView1.DataSource = dt;
textBox4.Text = dt.Rows.Count.ToString();
}
MessageBox.Show(textBox4.Text + " enregistrement(s) Touvé(s)");
}
private void button5_Click(object sender, EventArgs e)
{
dataGridView1.ClearSelection();
dataGridView1.DataSource = "";
cmd.Cancel();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
con.Close();
}
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
}
}
} |
Partager