Field with asterisks are required to be filled out

109 views Asked by At

enter image description here enter image description here

images are already attached

i copied this code already and took the sample fields like txtAccessionNumber.Text, txtISBN.Text, and txtTitle.Text as the field that required to be filled out, but then, i also tried to not put any data on the other fields like txtEdition.Text, txtRevision.Text, and txtVolume.Text because they are not on the code that required to be filled, that is why i left them empty to test it. but then it shows after i click the save button, it is now required to be filled also. why is that?

here's my code.

 private void inventory_add_Load(object sender, EventArgs e)
{

}

private void btnAddBooks_Click(object sender, EventArgs e)
{
    btnAddBooks_Click(sender, e, txtISBN);
}

private void btnAddBooks_Click(object sender, EventArgs e, TextBox txtISBN)
{
    if (string.IsNullOrWhiteSpace(txtAccessionNumber.Text) ||
        !Int64.TryParse(txtISBN.Text, out _) || 
        string.IsNullOrWhiteSpace(txtTitle.Text))
    {

        MessageBox.Show("Fields with asterisk (*) are required to be filled out.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    String AccessionNumber = txtAccessionNumber.Text;
        if (Int64.TryParse(txtISBN.Text, out long ISBN))
        {
        }
        else
        {
        }
        String Section = cbSection.Text;
        String Subject = txtSubject.Text;
        String Title = txtTitle.Text;
        String Author = txtAuthor.Text;
        String JointAuthor = txtJointAuthor.Text;
        String Publisher = txtPublisher.Text;
        String YearPublished = dtpYearPublished.Text;
        String Edition = txtEdition.Text;
        String Revision = txtRevision.Text;
        String Volume = txtVolume.Text;
        String CallNumber = txtCallNumber.Text;
        String ShelfNumber = txtShelfNumber.Text;
        String TypeOfAcquisition = cbTypeOfAcquisition.Text;
        String DateAcquired = dtpDateAcquired.Text;
        String DonorPrice = txtDonorPrice.Text;
        String Remarks = txtRemarks.Text;

        SqlConnection con = new SqlConnection();
        con.ConnectionString = "data source = LAPTOP-H2T3JL0H\\SQLEXPRESS; database = LIBRARYmanagementsystem; integrated security=True";
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;

        con.Open();
        cmd.CommandText = "insert into INV_ADDBOOKStable (AccessionNumber,ISBN,Section,Subject,Title,Author,JointAuthor,Publisher,YearPublished,Edition,Revision,Volume,CallNumber,ShelfNumber,TypeOfAcquisition,DateAcquired,DonorPrice,Remarks) values ('" + AccessionNumber + "'," + ISBN + ",'" + Section + "','" + Subject + "','" + Title + "','" + Author + "','" + JointAuthor + "','" + Publisher + "','" + YearPublished + "','" + Edition + "','" + Revision + "','" + Volume + "','" + CallNumber + "','" + ShelfNumber + "','" + TypeOfAcquisition + "','" + DateAcquired + "','" + DonorPrice + "','" + Remarks + "')";
        cmd.ExecuteNonQuery();
        con.Close();

        MessageBox.Show("Book Successfully Added!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        txtAccessionNumber.Clear();
        txtISBN.Clear();
        cbSection.SelectedIndex = -1;
        txtSubject.Clear();
        txtTitle.Clear();
        txtAuthor.Clear();
        txtJointAuthor.Clear();
        txtPublisher.Clear();
        dtpYearPublished.Value = DateTimePicker.MinimumDateTime;
        txtEdition.Clear();
        txtRevision.Clear();
        txtVolume.Clear();
        txtCallNumber.Clear();
        txtShelfNumber.Clear();
        cbTypeOfAcquisition.SelectedIndex = -1;
        dtpDateAcquired.Value = DateTimePicker.MinimumDateTime;
        txtDonorPrice.Clear();
        txtRemarks.Clear();

}

}

does anyone know what should i do???

i tried some suggestions already but it all doesn't work

0

There are 0 answers