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

SQL Con

The document is a C# ASP.NET web page code that handles basic CRUD operations for an employee database. It includes methods to insert, update, and delete employee records using SQL commands and displays success messages using message boxes. The database connection is established using a local SQL Server database file.

Uploaded by

Vijaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

SQL Con

The document is a C# ASP.NET web page code that handles basic CRUD operations for an employee database. It includes methods to insert, update, and delete employee records using SQL commands and displays success messages using message boxes. The database connection is established using a local SQL Server database file.

Uploaded by

Vijaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.VisualBasic;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
v11.0;AttachDbFilename=S:\\6001\\WebSite1\\App_Data\\Database.mdf;Integrated
Security=True");
SqlCommand cmd =con.CreateCommand();
con.Open();
cmd.CommandText="INSERT INTO Emp VALUES('"+TextBox1.Text
+"','"+TextBox2.Text+"')";
cmd.Connection=con;
int flag= cmd.ExecuteNonQuery();
if (flag == 1)
{
MessageBox.Show("Insterted successfuly");
}

}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect(Request.RawUrl);

}
protected void Button4_Click(object sender, EventArgs e)
{
String inp=Interaction.InputBox("Enter the id ","Search","",0,0);
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
v11.0;AttachDbFilename=S:\\6001\\WebSite1\\App_Data\\Database.mdf;Integrated
Security=True");
SqlCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "DELETE from Emp where Id=" +inp ;
cmd.Connection = con;
int flag = cmd.ExecuteNonQuery();
if (flag == 1)
{
MessageBox.Show("Deleted successfuly");
}

}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
v11.0;AttachDbFilename=S:\\6001\\WebSite1\\App_Data\\Database.mdf;Integrated
Security=True");
SqlCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "UPDATE Emp set Name ='" + TextBox2.Text + "' where Id = " +
int.Parse(TextBox1.Text);
cmd.Connection = con;
int flag = cmd.ExecuteNonQuery();
if (flag == 1)
{
MessageBox.Show("Updated successfuly");
}
}
}

You might also like