| 12
 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
 
 | private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Inserer le Numero");
            }else
                if (textBox1.Text != "")
                {
                    for (int row = 0; row < dataGridView1.Rows.Count; row++)
                    {
                        for (int col = 0; col < dataGridView1.Columns.Count; col++)
                        {
                            if (dataGridView1.Rows[row].Cells[col].Value != null &&
                              dataGridView1.Rows[row].Cells[col].Value.Equals(textBox1.Text.Trim()))
                            {
                                MessageBox.Show(" Le numero exist dejà ");
                            }
                        }
                    }
                }
 
                else
                    if (textBox2.Text == "")
                    {
                        MessageBox.Show("Inserer le Nom");
                    }
                    else
                        if (textBox3.Text == "")
                        {
                            MessageBox.Show("Inserer le Prenom");
                        }
 else
                        {
                            cazoranConn.Open();
                            OleDbCmd.Connection = cazoranConn;
                            OleDbCmd.CommandText = "insert into persoone (Numero, Nom ,Prenom,Etat) values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "' ,'" + this.comboBox1.Text + "');";
                            int temp = OleDbCmd.ExecuteNonQuery();
                            if (temp > 0)
                            {
                                textBox1.Text = null;
                                textBox2.Text = null;
                                textBox3.Text = null;
 
                                // show all 
                                MessageBox.Show("Record Successfuly Added");
                                dataGridView1.DataSource = null;
                                dataGridView1.Rows.Clear();
                                dataGridView1.Refresh();
 
                                OleDbDataAdapter dAdapter = new OleDbDataAdapter("select * from persoone", connParam);
                                OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
                                DataTable dataTable = new DataTable();
                                DataSet ds = new DataSet();
                                dAdapter.Fill(dataTable);
 
                                for (int i = 0; i < dataTable.Rows.Count; i++)
                                {
                                    dataGridView1.Rows.Add(dataTable.Rows[i][0], dataTable.Rows[i][1], dataTable.Rows[i][2], dataTable.Rows[i][3]);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Record Fail to Added");
                            }
                            cazoranConn.Close();
                        }
        } | 
Partager