void DeleteAuthor() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Delete from dbo.author_master_tbl Where author_id='" + TextBox_AuthorId.Text.Trim() + "'", con); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author Deleted successfully);</script>"); ClearForm(); AuthorTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
void UpdateAuthor() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Update dbo.author_master_tbl Set author_name=@author_name Where author_id='" + TextBox_AuthorId.Text.Trim() + "'", con); cmd.Parameters.AddWithValue("@author_name", TextBox_AuthorName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author Updated Successfully');</script>"); AuthorTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
void AddNewAuthor() { try{ SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Insert Into dbo.author_master_tbl(author_id, author_name) values(@author_id, @author_name)", con); cmd.Parameters.AddWithValue("@author_id", TextBox_AuthorId.Text.Trim()); cmd.Parameters.AddWithValue("@author_name", TextBox_AuthorName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author added Successfully');</script>"); ClearForm(); AuthorTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { AuthorTable.DataBind(); }