-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchCourse.cs
More file actions
50 lines (45 loc) · 1.69 KB
/
SearchCourse.cs
File metadata and controls
50 lines (45 loc) · 1.69 KB
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
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;
namespace TinyCollegeGUI
{
public partial class SearchCourse : Form
{
public SearchCourse()
{
InitializeComponent();
}
// Event handler for Find button
private void buttonFind_Click(object sender, EventArgs e)
{
using SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TinyCollegeDB"].ConnectionString);
using SqlDataAdapter adapter = new SqlDataAdapter(
// Tells system to SELECT info FROM the joined (or combined) Courses and Instructors tables
"SELECT * FROM Courses JOIN Instructors ON Courses.InstructorId = Instructors.InstructorId WHERE CourseID = @courseId", conn);
adapter.SelectCommand.Parameters.AddWithValue("@courseId", textBoxCourseID.Text);
DataTable courseTable = new DataTable();
adapter.Fill(courseTable);
if (courseTable.Rows.Count < 1)
{
labelCourseNameValue.Text = "No course found";
labelInstructorNameValue.Text = string.Empty;
}
else
{
DataRow dr = courseTable.Rows[0];
labelCourseNameValue.Text = dr["CourseName"].ToString();
labelInstructorNameValue.Text = dr["InstructorName"].ToString();
}
}
// Event handler for Close button
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}