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

1 Code

Code

Uploaded by

Holly Anderson
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)
39 views

1 Code

Code

Uploaded by

Holly Anderson
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/ 6

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;
using MySql.Data.MySqlClient;
namespace student
{
public partial class course : Form
{
String connection = "Server=localhost;Database=1rz14mca20;Uid=root;Pwd=m
ca";
MySqlConnection con;
MySqlCommand cmd;
public course()
{
InitializeComponent();
con = new MySqlConnection(connection);
}

private void Add_Click_1(object sender, EventArgs e)


{
con.Open();
try
{
cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO tbl_course(courseName) values(?co
urseName)";
cmd.Prepare();
cmd.Parameters.AddWithValue("?courseName", tcname.Text);
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
tcname.Clear();
con.Close();
}
}
private void show_Click_1(object sender, EventArgs e)
{
con.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter("select * from tbl_c
ourse", con);
DataSet ds = new DataSet();
adapter.Fill(ds, "c");

dataGridView1.DataSource = ds.Tables["c"];
con.Close();
}
private void Delete_Click_1(object sender, EventArgs e)
{
con.Open();
try
{
cmd = con.CreateCommand();
cmd.CommandText = "delete from tbl_course where courseName=?cour
seName";
cmd.Prepare();
cmd.Parameters.AddWithValue("?courseName", tcname.Text);
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
// tcname.Clear();
tcname.Clear();
con.Close();
}
}
}
}

particuler_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;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace student
{
public partial class particular_course : Form
{
MySqlConnection con = new MySqlConnection("server=localhost;database=1rz
14mca20;uid=root;pwd=mca");
MySqlCommand cmd;
public particular_course()
{
InitializeComponent();
con.Open();
cmd = new MySqlCommand("Select * from tbl_course", con);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())

{
comboBox1.Items.Add(reader.GetString("courseID") + " " + reader
.GetString("courseName"));
}
reader.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewC
ellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MySqlDataAdapter adpt = new MySqlDataAdapter("select * from tbl_stud
ent where courseID=(Select courseID from tbl_course where courseID='" + ((comboB
ox1.Text).Split(' '))[0] + "');", con);
DataSet ds = new DataSet();
adpt.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
public void display()
{
MySqlDataAdapter adpt = new MySqlDataAdapter("select * from book", c
on);
DataSet ds = new DataSet();
adpt.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
}
}

particular_year.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;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace student
{
public partial class particular_year : Form
{
MySqlConnection con = new MySqlConnection("server=localhost;database=1rz
14mca20;uid=root;pwd=mca");
MySqlCommand cmd;
public particular_year()
{
InitializeComponent();

con.Open();
cmd = new MySqlCommand("Select * from tbl_student group by yearadm",
con);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader.GetString("yearadm"));
}
reader.Close();
}
private void button1_Click(object sender, EventArgs e)
{
MySqlDataAdapter adpt = new MySqlDataAdapter("(select * from tbl_stu
dent where yearadm= '" +comboBox1.Text+"');", con);
DataSet ds = new DataSet();
adpt.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
}
}
stud.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;
using MySql.Data.MySqlClient;
namespace student
{
public partial class stud : Form
{
String connection = "Server=localhost;Database=1rz14mca20;Uid=root;Pwd=m
ca";
MySqlConnection con;
MySqlCommand cmd;
public stud()
{
InitializeComponent();
con = new MySqlConnection(connection);
con.Open();
cmd = new MySqlCommand("Select * from tbl_course", con);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader.GetString("courseID") + " " + reader
.GetString("courseName"));
}
reader.Close();
con.Close();
}

private void Delete_Click(object sender, EventArgs e)


{
con.Open();
try
{
cmd = con.CreateCommand();
cmd.CommandText = "delete from tbl_student where usn=?usn";
cmd.Prepare();
cmd.Parameters.AddWithValue("?usn", tusn.Text);
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
tusn.Clear();
tsname.Clear();
taddress.Clear();
tyear.Clear();
//tcid.Clear();
con.Close();
}
}
private void Add_Click(object sender, EventArgs e)
{
con.Open();
try
{
cmd = con.CreateCommand();
cmd.CommandText = "insert into tbl_student(usn,studName,address,
courseID,yearadm) values(?usn,?name,?address,?courseId,?yearofadm)";
cmd.Prepare();
cmd.Parameters.AddWithValue("?usn", tusn.Text);
cmd.Parameters.AddWithValue("?name", tsname.Text);
cmd.Parameters.AddWithValue("?address", taddress.Text);
cmd.Parameters.AddWithValue("?courseId", ((comboBox1.Text).Split
(' '))[0]);
cmd.Parameters.AddWithValue("?yearofadm", tyear.Text);
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
tusn.Clear();
tsname.Clear();
taddress.Clear();
tyear.Clear();
//comboBox1.Clear();
con.Close();
}
}

private void show_Click(object sender, EventArgs e)


{
con.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter("select * from tbl_s
tudent", con);
DataSet ds = new DataSet();
adapter.Fill(ds, "c");
dataGridView1.DataSource = ds.Tables["c"];
con.Close();
}
}
}

You might also like