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

SQL Con

The document is a C# ASP.NET web page code that handles employee database operations such as inserting, updating, and deleting records from an SQL database. It includes event handlers for button clicks that execute SQL commands based on user input. The code also provides feedback to the user via message boxes upon successful database operations.

Uploaded by

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

SQL Con

The document is a C# ASP.NET web page code that handles employee database operations such as inserting, updating, and deleting records from an SQL database. It includes event handlers for button clicks that execute SQL commands based on user input. The code also provides feedback to the user via message boxes upon successful database operations.

Uploaded by

Vijaya
Copyright
© © All Rights Reserved
Available Formats
Download as 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;Int
egrated 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;Int
egrated 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;Int
egrated 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