0% found this document useful (0 votes)
2 views

ال

The code initializes a form that allows users to select a department from a combo box, specifically 'SW' and 'IT'. Upon selection, it retrieves and displays students from a database based on the chosen department. The data is fetched using a SQL query and displayed in a DataGridView control.
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)
2 views

ال

The code initializes a form that allows users to select a department from a combo box, specifically 'SW' and 'IT'. Upon selection, it retrieves and displays students from a database based on the chosen department. The data is fetched using a SQL query and displayed in a DataGridView control.
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/ 1

private void Form3_Load(object sender, EventArgs e)

{
// ‫إضافة الأقسام يدوًيا عند تحميل النموذج‬
comboBox1.Items.Add("SW");
comboBox1.Items.Add("IT");
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
if (comboBox1.SelectedItem != null) // ‫التأكد من اختيار قسم‬
{
string selectedDepartment = comboBox1.SelectedItem.ToString(); // ‫جلب اسم‬
‫القسم المختار‬
LoadStudentsByDepartment(selectedDepartment); // ‫تحميل الطالب حسب القسم‬
}
}

private void LoadStudentsByDepartment(string department)


{
using (SqlConnection con = new SqlConnection("Data Source=DESKTOP-30OSUJ5\\
SQLEXPRESS;Initial Catalog=studentm;Integrated Security=True"))
{
string query = "SELECT * FROM studentn WHERE name7 = @Department"; // ‫جلب‬
‫الطالب حسب القسم‬
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@Department", department);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

dataGridView1.DataSource = dt; // ‫ عرض البيانات في‬DataGridView


}
}

You might also like