0% found this document useful (0 votes)
14 views4 pages

CURD Operations

The document outlines a C# Windows Forms application for performing CRUD operations on student data using the .NET Framework. It includes methods for inserting, updating, deleting, and resetting student records in a SQL database. The application connects to a local SQL database and provides a user interface for data entry and manipulation.

Uploaded by

dsingh388
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

CURD Operations

The document outlines a C# Windows Forms application for performing CRUD operations on student data using the .NET Framework. It includes methods for inserting, updating, deleting, and resetting student records in a SQL database. The application connects to a local SQL database and provides a user interface for data entry and manipulation.

Uploaded by

dsingh388
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

23SOECE13026 Enterprise Computing Through .

NET Framework (CE525)


Curd Operation

txtEnrlNo

txtName

txtAge

txtCity

btnInsert btnDelete

btnUpdate btnReset

using System.Data;
using System.Data.SqlClient;

namespace DemoCurd
{
public partial class StudentDetails : Form
{

DEV VYAS Computer Engineering


23SOECE13026 Enterprise Computing Through .NET Framework (CE525)
public static string path = @"Data Source=(LocalDB)\
MSSQLLocalDB;AttachDbFilename=F:\.NetProjects\DemoCurd\
Curd.mdf;Integrated Security=True";
public SqlConnection con = new SqlConnection(path);
public StudentDetails()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
}
private void btnInsert_Click(object sender, EventArgs e)
{
string insquery = "insert into
student(enrlno,Name,age,city)values(@enrlno,@Name,@age,@city)";
con.Open();
SqlCommand cmd = new SqlCommand(insquery, con);
cmd.Parameters.AddWithValue("@enrlno", enrlno.Text);
cmd.Parameters.AddWithValue("@Name", name.Text);
cmd.Parameters.AddWithValue("@age", int.Parse(age.Text));
cmd.Parameters.AddWithValue("@city", city.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("inserted successfuly");
clearall();
}

private void clearall()


{
enrlno.Clear();
name.Clear();
age.Clear();
city.Clear();
}

private void btnUpdate_Click(object sender, EventArgs e)


{

DEV VYAS Computer Engineering


23SOECE13026 Enterprise Computing Through .NET Framework (CE525)
string updtquery = "update student set Name='" + name.Text + "',age='" +
Convert.ToInt32(age.Text) + "',city='" + city.Text + "' where enrlno='" + enrlno.Text
+ "'";
con.Open();
SqlCommand upt = new SqlCommand(updtquery, con);
upt.ExecuteNonQuery();
con.Close();
MessageBox.Show("updated successfuly");
clearall();
}

private void delete_Click(object sender, EventArgs e)


{
string updtquery = "delete student where enrlno='" + enrlno.Text + "'";
con.Open();
SqlCommand upt = new SqlCommand(updtquery, con);
upt.ExecuteNonQuery();
con.Close();
MessageBox.Show("deleted");
clearall();
}

private void reset_Click(object sender, EventArgs e)


{
clearall();
}
}
}

DEV VYAS Computer Engineering


23SOECE13026 Enterprise Computing Through .NET Framework (CE525)

DEV VYAS Computer Engineering

You might also like