Hello,
I have 2 forms. One is called librarySettings, and another one is called loanBook. When the user wants to loan a book, l want to be able to receive 2 variables from this form, which is DaysBorrowed, and OverdueFine. This way if the settings are changed then the loanbook form will have the updated variables.
This is what l have done, and l have done this before, but can't seen to get it to work. Don't know what is going on here.
LibrarySettings form.
//Set up 2 public proceduresCode:This load the variables data from a database, so that the settings can be updated to a database. private void frmLibrarySettings_Load(object sender, System.EventArgs e) { try { cnn.Open(); OleDbCommand cmd = cnn.CreateCommand(); OleDbDataAdapter da = new OleDbDataAdapter(); DataTable dt = new DataTable(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM LibrarySettings"; da.SelectCommand = cmd; da.Fill(dt); upDDays.Value = Convert.ToInt16(dt.Rows[0]["Days"]); //load into a numericUpDown control upDFine.Value = Convert.ToInt16(dt.Rows[0]["Fine"]); } catch ( OleDbException ex ) { MessageBox.Show(ex.Message); } catch ( Exception ex ) { MessageBox.Show(ex.Message); } }
That is all for the library settings formCode:public int fineAmount { get { return Convert.ToInt16(upDFine.Value); } } public int DaysToBorrow { get { return Convert.ToInt16(upDDays.Value); } }
for the loanbook form.
I have declared this in the form at the top of the class
Find out how long the book can be loaned for.Code:frmLibrarySettings getLibraryDetails = null; //Finds the day and fine amount that has been set in the library settings form
The error message l get when this code is executed is " Object reference not set to an instance of an object."Code:int loanDays = 0; loanDays = getLibraryDetails.DaysToBorrow; //Get the days the book can be loaned for - error occurs here
Not sure what l am doing wrong. Hope someone can help
Thanks in advance,
Steve




Reply With Quote