
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.Data; namespace SampleProject { public partial class Personal_Info : System.Web.UI.Page { // CONNECT DATA BASE STRING SqlConnection con = new SqlConnection(@"Data Source=CHARLES\SQLEXPRESS;Initial Catalog=ASPCRUD;Integrated Security=True;Pooling=False"); protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { RefreshTable(); Lbl_TransactionMessage.Text = ""; } } // BUTTON ADD protected void btn_Submit_Click(object sender, EventArgs e) { con.Open(); string str = "INSERT INTO Tbl_Employee values('" + tb_Lastname.Text + "','" + DDL_gender.Text + "','" + DDL_CivilStats.Text + "','" + tb_ContactNum.Text + "','" + DDL_month.Text + " " + "', '" + DDL_day.Text + "," + "', '" + DDL_year.Text + "')"; SqlCommand cmd = new SqlCommand(str, con); Lbl_TransactionMessage.Text = "Record Inserted Successfully"; cmd.ExecuteNonQuery(); con.Close(); ClearTextField(); RefreshTable(); } // BUTTON RESET protected void btn_Reset_Click(object sender, EventArgs e) { tb_Lastname.Text = string.Empty; tb_ContactNum.Text = string.Empty; DDL_CivilStats.SelectedIndex = 0; DDL_day.SelectedIndex = 0; DDL_gender.SelectedIndex = 0; DDL_month.SelectedIndex = 0; DDL_year.SelectedIndex = 0; Lbl_ID.Text = ""; } //REFRESH TABLE public void RefreshTable() { con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Tbl_Employee", con); DataTable dt = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); con.Close(); } // SELECT FILE IN TABLE protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { Lbl_ID.Text = GridView1.SelectedRow.Cells[0].Text; tb_Lastname.Text = GridView1.SelectedRow.Cells[1].Text; DDL_gender.Text = GridView1.SelectedRow.Cells[2].Text; DDL_CivilStats.Text = GridView1.SelectedRow.Cells[3].Text; tb_ContactNum.Text = GridView1.SelectedRow.Cells[4].Text; DDL_month.Text = GridView1.SelectedRow.Cells[5].Text; DDL_day.Text = GridView1.SelectedRow.Cells[6].Text; DDL_year.Text = GridView1.SelectedRow.Cells[7].Text; Lbl_TransactionMessage.Text = ""; } //CLEAR FILLED public void ClearTextField() { tb_Lastname.Text = ""; tb_ContactNum.Text = ""; DDL_CivilStats.SelectedIndex = 0; DDL_day.SelectedIndex = 0; DDL_gender.SelectedIndex = 0; DDL_month.SelectedIndex = 0; DDL_year.SelectedIndex = 0; Lbl_ID.Text = ""; } // BUTTON UPDATE protected void btn_Update_Click(object sender, EventArgs e) { con.Open(); string str = "UPDATE Tbl_Employee SET LastName = '" + tb_Lastname.Text + "',Gender = '" + DDL_gender.Text + "',CivilStatus = '" + DDL_CivilStats.Text + "',ContactNumber = '" + tb_ContactNum.Text + "',Month = '" + DDL_month.Text + "',Day = '" + DDL_day.Text + "',Year = '" + DDL_year.Text + "' WHERE EmployeeID = '" + Lbl_ID.Text + "'"; SqlCommand cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); Lbl_TransactionMessage.Text = "Record Updated Successfully"; con.Close(); ClearTextField(); RefreshTable(); } //BUTTON DELETE protected void btn_Delete_Click(object sender, EventArgs e) { con.Open(); SqlCommand cmd = new SqlCommand("DELETE FROM Tbl_Employee WHERE EmployeeID ='" + Lbl_ID.Text + "'", con); Lbl_TransactionMessage.Text = "Record Deleted Successfully"; cmd.ExecuteNonQuery(); con.Close(); ClearTextField(); RefreshTable(); } } }
No recent activity.
Articles, blogs, videos and forum posts show up here.
No expertise to show yet.
This is worked out from what a member publishes.