private void BtnSave_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Are you sure you want to save this record?", "Saving Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //open connection to the database cn.Open(); //command to be executed on the database cm = new SqlCommand("INSERT INTO tblBook VALUES (@bktitle, @bkedition, @bkgenre, @bkauthor, @bkpublisher, @bkyear, @bkISBN, @bkcopies)", cn); //set parameters value cm.Parameters.AddWithValue("@bktitle", txtBookTitle.Text); cm.Parameters.AddWithValue("@bkedition", txtEdition.Text); cm.Parameters.AddWithValue("@bkgenre", txtGenre.Text); cm.Parameters.AddWithValue("@bkauthor", txtAuthor.Text); cm.Parameters.AddWithValue("@bkpublisher", txtPublisher.Text); cm.Parameters.AddWithValue("@bkyear", int.Parse(txtYear.Text)); cm.Parameters.AddWithValue("@bkisbn", txtISBN.Text); cm.Parameters.AddWithValue("@bkcopies", txtCopies.Text); //ask db to execute query cm.ExecuteNonQuery(); //close connection cn.Close(); MessageBox.Show("Record has been sucessfully saved!"); Clear(); frmlist.LoadRecords(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }