void AddNewPublisher() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Insert Into dbo.publisher_master_tbl(publisher_id, publisher_name) values(@publisher_id, @publisher_name)", con); cmd.Parameters.AddWithValue("@publisher_id", TextBox_PublisherId.Text.Trim()); cmd.Parameters.AddWithValue("@publisher_name", TextBox_PublisherName.Text.Trim()); cmd.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert('Author added Successfully');</script>"); ClearForm(); PublisherTable.DataBind(); } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
void DeletePublisherById() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Delete from dbo.publisher_master_tbl Where publisher_id='" + TextBox_PublisherId.Text.Trim() + "'", con); int result = cmd.ExecuteNonQuery(); con.Close(); if (result > 0) { Response.Write("<script>alert('Publisher Deleted Successfully');</script>"); ClearForm(); PublisherTable.DataBind(); } else { Response.Write("<script>alert('Publisher Id does not Exist');</scriot>"); } } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
void UpdatePublisherById() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Update dbo.publisher_master_tbl Set publisher_name=@publisher_name Where publisher_id='" + TextBox_PublisherId.Text.Trim() + "'", con); cmd.Parameters.AddWithValue("@publisher_name", TextBox_PublisherName.Text.Trim()); int result = cmd.ExecuteNonQuery(); con.Close(); if (result > 0) { Response.Write("<script>alert('Publisher Updated Successfully');</script>"); PublisherTable.DataBind(); } else { Response.Write("<script>alert('Publisher Id does not Exist');</script>"); } } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { PublisherTable.DataBind(); }