} //AddNewAuthor private void UpdateAuthor() { // Backend codes for UpdateAuthor Page Button. //Error Handling and Validation codes for the database. try { //connecting the UpdateAuthor Page to the database. SqlConnection con = new SqlConnection(strcon); //checking if the UpdateAuthor Page is connected to the database. if (con.State == ConnectionState.Closed) { con.Open(); } //if_con //Firing the SQl Query SqlCommand cmd = new SqlCommand("UPDATE tbl_author SET author_name=@author_name WHERE author_id='" + AuthorID.Text.Trim() + "'", con); SqlParameter sqlParameterName = cmd.Parameters.AddWithValue("@author_name", AuthorName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); GridAuthor.DataBind(); Response.Write("<script>alert('" + AuthorName.Text.Trim() + "' + ' is successfully updated.' ); </script>"); ClearForm(); } //try catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "'); </script>"); ClearForm(); } //catch }//UpdateAuthor
}//BtnGO //defined method. private void AddNewAuthor() { // Backend codes for AddNewAuthor Page Button. //Error Handling and Validation codes for the database. try { //connecting the AuthorManagement Page to the database. SqlConnection con = new SqlConnection(strcon); //checking if the AuthorManagement Page is connected to the database. if (con.State == ConnectionState.Closed) { con.Open(); }//if_con //Firing the SQl Query SqlCommand cmd = new SqlCommand("INSERT INTO tbl_author(author_id,author_name) values(@author_id,@author_name)", con); SqlParameter sqlParameterId = cmd.Parameters.AddWithValue("@author_id", AuthorID.Text.Trim()); SqlParameter sqlParameterName = cmd.Parameters.AddWithValue("@author_name", AuthorName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('" + AuthorName.Text.Trim() + "' + ' Successfully added.' ); </script>"); GridAuthor.DataBind(); ClearForm(); }//try catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "'); </script>"); ClearForm(); } //catch } //AddNewAuthor
protected void ddlSelect_SelectedIndexChanged(object sender, EventArgs e) { DataAccessSQL dbAccess = new DataAccessSQL(); if (ddlSelect.SelectedValue.Trim() == "ALL") { GridAuthor.DataSource = dbAccess.ExecuteSelectCommand("GetAuthors", CommandType.StoredProcedure); } else { SqlParameter[] param = new SqlParameter[] { new SqlParameter("@state", ddlSelect.SelectedValue) }; GridAuthor.DataSource = dbAccess.ExecuteParamerizedSelectCommand("GetAuthorByState", CommandType.StoredProcedure, param); GridAuthor.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataAccessSQL dbAccess = new DataAccessSQL(); ddlSelect.DataSource = dbAccess.ExecuteSelectCommand("GetAuthorStates", CommandType.StoredProcedure); ddlSelect.DataTextField = "state"; ddlSelect.DataValueField = "state"; ddlSelect.DataBind(); ddlSelect.Items.Insert(0, new ListItem("--Select One--", "0")); GridAuthor.DataSource = dbAccess.ExecuteSelectCommand("GetAuthors", CommandType.StoredProcedure); GridAuthor.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { //Databind code_Refresh. GridAuthor.DataBind(); }