0% found this document useful (0 votes)
12 views2 pages

Testconnection VS

This document contains a C# Windows Forms application code that connects to a SQL Server database to manage student data. It includes functionalities to insert student records into the 'Etudiant' table and display them in a DataGridView. The application initializes a connection to the database and handles user interactions through button clicks and form loading events.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Testconnection VS

This document contains a C# Windows Forms application code that connects to a SQL Server database to manage student data. It includes functionalities to insert student records into the 'Etudiant' table and display them in a DataGridView. The application initializes a connection to the database and handles user interactions through button clicks and form loading events.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace APPLICATIONBD
{
public partial class Form1 : Form
{
SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-
CE6NR4Q;Initial Catalog=ECOLE;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;M
ultiSubnetFailover=False");
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
dis_data();
}

private void label10_Click(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Etudiant values('" + textBox1.Text +
"','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" +
textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text +
"','" + textBox9.Text + "')";
cmd.ExecuteNonQuery();
conn.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox9.Text = "";

dis_data();
MessageBox.Show("insertion validée");
}
private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{

}
public void dis_data()
{

conn.Open();
SqlCommand cmd = conn.CreateCommand();

cmd.CommandType = CommandType.Text;

cmd.CommandText = "select * from Etudiant";

cmd.ExecuteNonQuery();
DataTable d = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(d);
dataGridView1.DataSource = d;
conn.Close();
}
}
}

You might also like