You are on page 1of 15

Ex.

No: 2 Consider the Database STUDENT consisting of following tables:


Date: tbl_Course (CourseID:int, CourseName: string)
tbl_Student (USN: string, StudName: string, Address:
string,CourseID: int,YrOfAdmsn: int)
Develop suitable windows application using C#.NET having following options:
a) Entering new course details.
b) Entering new student details.
c) Display the details of students (in a Grid) who belong to a particular course.
d) Display the details the students who have taken admission in a particular year.

Aim:

Alogorithm:
CommonData.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace Student
{
class CommonData
{
public static DataTable Stud;
public static DataTable Course;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Student
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
}
Output:

MAIN FORM:
Program:

Main.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Student
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}

private void btnAddStudent_Click(object sender, EventArgs e)


{
Student st = new Student();
st.Show();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnDisplayStud_Click(object sender, EventArgs e)


{
studentDetails std = new studentDetails();
std.Show();
}

private void btnAddCourse_Click(object sender, EventArgs e)


Output:

Student-Form:
{
Course cr = new Course();
cr.Show();
}
private void btnDisplayYr_Click(object sender, EventArgs e)
{
studentsYearWise sty = new studentsYearWise();
sty.Show();
}
private void Main_Load(object sender, EventArgs e)
{
}
}
}
Student.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Student
{
public partial class Student : Form
{
public Student()
{
CommonData.Stud = new DataTable();
CommonData.Stud.Columns.Add("USN");
CommonData.Stud.Columns.Add("StudName");
CommonData.Stud.Columns.Add("Address");
CommonData.Stud.Columns.Add("CourseID");
CommonData.Stud.Columns.Add("YrOfAdmsn");
InitializeComponent()
}
private void btnClear_Click(object sender, EventArgs e)
{
}

private void btnClose_Click(object sender, EventArgs e)


{
this.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
DataRow dr = CommonData.Stud.NewRow();
dr[0] = txtUID.Text;
dr[1] = txtName.Text;
dr[2] = txtAddress.Text;
dr[3] = int.Parse(txtCid.Text);
dr[4] = int.Parse(txtYear.Text);
CommonData.Stud.Rows.Add(dr);
MessageBox.Show("A new record Inserted");
}
private void Student_Load(object sender, EventArgs e)
{
int cnt = CommonData.Course.Rows.Count;
for (int r = 0; r < cnt; r++)
{
DataRow dr = CommonData.Course.Rows[r];
txtCid.Items.Add(dr[0]);
}
}
private void btnClear_Click_1(object sender, EventArgs e)
{
txtUID.Text = "";
txtName.Text = "";
txtCid.Text = "";
txtAddress.Text = "";
txtYear.Text = "";
}
}
}
Output:

Course-Form:
Course.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Student
{
public partial class Course : Form
{
public Course()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)


{
this.Close();
private void btnClear_Click(object sender, EventArgs e)
{
txtCid.Text = "";
txtCName.Text = "";
}

private void btnAdd_Click(object sender, EventArgs e)


{
DataRow dr = CommonData.Course.NewRow();
dr[0] = txtCid.Text;
dr[1] = txtCName.Text;
CommonData.Course.Rows.Add(dr);
MessageBox.Show("Row Inserted");
Output:

Student-Details

v
}

private void Course_Load(object sender, EventArgs e)


{
CommonData.Course = new DataTable();
CommonData.Course.Columns.Add("CourseID");
CommonData.Course.Columns.Add("CourseName");
}
}
}

StudentDetails.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Student
{
public partial class studentDetails : Form
{
public studentDetails()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
DataRow[] dr = CommonData.Stud.Select("CourseID=" + "'" + cmbCourse.Text

+ "'"); //CourseID='10'
Output:

Student-Year Wise
gridData.DataSource = dr.CopyToDataTable();
gridData.Refresh();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}

private void studentDetails_Load(object sender, EventArgs e)


{
int cnt = CommonData.Course.Rows.Count;
for (int r = 0; r < cnt; r++)
{
DataRow dr = CommonData.Course.Rows[r];
cmbCourse.Items.Add(dr[0]);
}
}
}
}
StudentsYearWise.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Student
{
public partial class studentsYearWise : Form
{
public studentsYearWise()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
this.Close();
}

private void button1_Click(object sender, EventArgs e)


{
DataRow[] dr = CommonData.Stud.Select("YrOfAdmsn=" + "'" + cmbYear.Text
+ "'");
gridData.DataSource = dr.CopyToDataTable();
gridData.Refresh();
}

private void studentsYearWise_Load(object sender, EventArgs e)


{
int cnt = CommonData.Stud.Rows.Count;
for (int r = 0; r < cnt; r++)
{
DataRow dr = CommonData.Stud.Rows[r];
cmbYear.Items.Add(dr[4]);
}
}
}
}
Result:

You might also like