IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Actualisation datagridx c#


Sujet :

C#

  1. #1
    Membre à l'essai

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2017
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 15
    Points : 19
    Points
    19
    Billets dans le blog
    1
    Par défaut Actualisation datagridx c#
    bonsoir les amis, j'ai un prob d'actualisation de la grille, a chaque nouvelle recherche les ancien recherche se repete
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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();
            }
        } 
    }
    help plz

  2. #2
    Membre du Club Avatar de coco1397
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2016
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2016
    Messages : 58
    Points : 67
    Points
    67

Discussions similaires

  1. [SWT] actualiser une fenêtre
    Par cootchy dans le forum SWT/JFace
    Réponses: 7
    Dernier message: 16/05/2004, 00h53
  2. [MFC] Probleme d'actualisation d'une listbox
    Par Robleplongeur dans le forum MFC
    Réponses: 5
    Dernier message: 13/05/2004, 15h15
  3. [ JSP ][ Débutant ] Liste déroulante + actualisation de page
    Par captainpouet dans le forum Servlets/JSP
    Réponses: 4
    Dernier message: 17/04/2004, 20h51
  4. [CR7]Actualisation des données depuis VB
    Par elifqaoui dans le forum SDK
    Réponses: 4
    Dernier message: 24/11/2003, 14h44
  5. Actualisation d'une liste "dépendante".
    Par Trilby dans le forum ASP
    Réponses: 6
    Dernier message: 19/11/2003, 19h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo