Sie sind auf Seite 1von 2

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.Windows.Forms;
using System.Data.SqlClient;

namespace Exemple1ADOConnecté
{
public partial class Form1 : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;

public Form1()
{
InitializeComponent();
//con = new SqlConnection(@"Server=DESKTOP-
BOJCFG6\\SQLEXPRESS;DataBase=EFM;Integrated Security=true");
con = new SqlConnection(@"Data Source=DESKTOP-
BOJCFG6\SQLEXPRESS;Initial Catalog=EFM;Integrated Security=True");
cmd = new SqlCommand("", con);
}

private void Form1_Load(object sender, EventArgs e)


{

}
private void vider()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
cmd.CommandText = "insert into medecin values(" +
int.Parse(textBox1.Text) +
",'"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"','
"+textBox6.Text+"')";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Opération a réussie");
vider();
}

private void button2_Click(object sender, EventArgs e)


{
cmd.CommandText = "update medecin set nomMd='" + textBox2.Text +
"',prenomMd='" + textBox3.Text + "',specialité='" + textBox4.Text + "',loginMd='" +
textBox5.Text + "',passMd='" + textBox6.Text + "' where numMedecin=" +
int.Parse(textBox1.Text) ;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Opération a réussie");
vider();
}

private void button3_Click(object sender, EventArgs e)


{
cmd.CommandText = "delete from medecin where numMedecin=" +
int.Parse(textBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Opération a réussie");
vider();
}

private void button4_Click(object sender, EventArgs e)


{
cmd.CommandText = "select * from medecin";
con.Open();
dr= cmd.ExecuteReader();

DataTable dt = new DataTable();


dt.Load(dr);
dataGridView1.DataSource = dt;

con.Close();
}
}
}

Das könnte Ihnen auch gefallen