public bool InsertAuthorToDB(AuthorsBAL author) { bool status = false; SqlConnection cn = new SqlConnection("Data Source=PLATOW42L0560;Initial Catalog=pubs;Integrated Security=True"); try { SqlCommand cmd = new SqlCommand("sp_Insert_Author", cn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Author_id", author.AuthorID); cn.Open(); cmd.ExecuteNonQuery(); status = true; } catch (Exception ex) { throw new Exception(ex.Message); } finally { cn.Close(); } return(status); }
private void button1_Click(object sender, EventArgs e) { try { AuthorsBAL a = new AuthorsBAL(); a.AuthorID = txt_a_id.Text.Trim(); a.AuthorFirstName = txt_a_fname.Text.Trim(); a.AuthorLastName = txt_a_lname.Text.Trim(); a.AuthorPhone = txt_a_phone.Text.Trim(); a.AuthorAddress = txt_a_address.Text.Trim(); a.AuthorCity = txt_a_city.Text.Trim(); a.AuthorState = txt_a_state.Text.Trim(); a.AuthorZip = txt_a_zip.Text.Trim(); a.AuthorContract = Convert.ToBoolean(txt_a_contract); AuthorDAL dal = new AuthorDAL(); bool astatus = dal.InsertAuthorToDB(a); if (astatus == true) { MessageBox.Show("Done"); } else { MessageBox.Show("CheckData"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }