11 PRC

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

2CEIT403: Application Development Tools Practical-11

A.Y. 2022-2023

Practical-11
Aim: Develop a form which search and display student list in gridview
Code:
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;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
SqlConnection sc = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\vridd\\source\\repos\
\WindowsFormsApp2\\WindowsFormsApp2\\vriddhi.mdf;Integrated Security=True");
sc.Open();
string gender;
string DOB;
if (radioButton1.Checked == true)
{
gender = radioButton1.Text;
}
else
{
gender = radioButton2.Text;
}

Name:Manthan Mehta 1 | Page


Enrollment No: 21012021048
Batch/Branch: (4AB6)/IT
2CEIT403: Application Development Tools Practical-11
A.Y. 2022-2023

DOB = comboBox3.Text + "/" + comboBox4.Text + "/" + comboBox5.Text;


string q = "insert into info values('" + textBox1.Text + "','" + textBox2.Text + "','" +
comboBox1.SelectedItem.ToString() + "','" + comboBox2.SelectedItem.ToString() + "','"
+ textBox5.Text + "','" + textBox3.Text + "','" + gender.ToString() + "','" + DOB.ToString()
+ "')";
SqlCommand cmd = new SqlCommand(q, sc);
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
sc.Close();
}

private void Form1_Load(object sender, EventArgs e)


{
for (int i = 1; i <= 31; i++)
{
comboBox3.Items.Add(i.ToString());
}
for (int i = 1; i <= 12; i++)
{
comboBox4.Items.Add(i.ToString());
}
for (int i = 1995; i <= 2050; i++)
{
comboBox5.Items.Add(i.ToString());
}
for(int i = 1; i <= 8; i++)
{
comboBox2.Items.Add(i.ToString());
}
}

private void button2_Click(object sender, EventArgs e)


{
SqlConnection sc = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\vridd\\source\\repos\
\WindowsFormsApp2\\WindowsFormsApp2\\vriddhi.mdf;Integrated Security=True");
sc.Open();
string gender;
string DOB;
if (radioButton1.Checked == true)
Name:Manthan Mehta 2 | Page
Enrollment No: 21012021048
Batch/Branch: (4AB6)/IT
2CEIT403: Application Development Tools Practical-11
A.Y. 2022-2023

{
gender = radioButton1.Text;
}
else
{
gender = radioButton2.Text;
}
DOB = comboBox3.Text + "/" + comboBox4.Text + "/" + comboBox5.Text;
string q = "update info set Enrollmentno='" + textBox1.Text + "',Name='" +
textBox2.Text + "',Branch='" + comboBox1.SelectedItem.ToString() + "',Semester='" +
comboBox2.SelectedItem.ToString() + "',Address='" + textBox5.Text + "',Mobileno='" +
textBox3.Text + "',Gender='" + gender.ToString() + "',DOB='" + DOB.ToString() + "'
where Enrollmentno='" + textBox4.Text + "'";
SqlCommand cmd = new SqlCommand(q, sc);
cmd.ExecuteNonQuery();
MessageBox.Show("Updated");
sc.Close();
}

private void button3_Click(object sender, EventArgs e)


{
SqlConnection sc = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\vridd\\source\\repos\
\WindowsFormsApp2\\WindowsFormsApp2\\vriddhi.mdf;Integrated Security=True");
sc.Open();
string q = "delete from info where Enrollmentno='" + textBox4.Text + "'";
SqlCommand cmd = new SqlCommand(q, sc);
cmd.ExecuteNonQuery();
MessageBox.Show("Deleted");
sc.Close();
}

private void button4_Click(object sender, EventArgs e)


{
SqlConnection sc = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\vridd\\source\\repos\
\WindowsFormsApp2\\WindowsFormsApp2\\vriddhi.mdf;Integrated Security=True");
sc.Open();
string q = "Select * From info where Enrollmentno='" + textBox4.Text + "'";
SqlDataAdapter sda = new SqlDataAdapter(q,sc);
Name:Manthan Mehta 3 | Page
Enrollment No: 21012021048
Batch/Branch: (4AB6)/IT
2CEIT403: Application Development Tools Practical-11
A.Y. 2022-2023

DataTable tb = new DataTable();


sda.Fill(tb);
dataGridView1.DataSource = tb;
sc.Close();

}
private void button5_Click(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\vridd\\source\\repos\
\WindowsFormsApp2\\WindowsFormsApp2\\vriddhi.mdf;Integrated Security=True");
sc.Open();
string q = "Select * From info where Name like'" + textBox6.Text + "%'";
SqlDataAdapter sda = new SqlDataAdapter(q, sc);
DataTable tb = new DataTable();
sda.Fill(tb);
dataGridView1.DataSource = tb;
sc.Close();
}

}
}
Output:

Name:Manthan Mehta 4 | Page


Enrollment No: 21012021048
Batch/Branch: (4AB6)/IT
2CEIT403: Application Development Tools Practical-11
A.Y. 2022-2023

Name:Manthan Mehta 5 | Page


Enrollment No: 21012021048
Batch/Branch: (4AB6)/IT
2CEIT403: Application Development Tools Practical-11
A.Y. 2022-2023

Name:Manthan Mehta 6 | Page


Enrollment No: 21012021048
Batch/Branch: (4AB6)/IT

You might also like