Results 1 to 5 of 5

Thread: Receiving data from variable from another form. [* Resovled *]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Receiving data from variable from another form. [* Resovled *]

    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.

    Code:
    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);
    			}
    		}
    //Set up 2 public procedures
    Code:
                    public int fineAmount
    		{
    			get
    			{
    				return Convert.ToInt16(upDFine.Value);
    			}
    		}
    
    		public int DaysToBorrow
    		{
    			get
    			{
    				return Convert.ToInt16(upDDays.Value);
    			}
    		}
    That is all for the library settings form


    for the loanbook form.

    I have declared this in the form at the top of the class
    Code:
    frmLibrarySettings getLibraryDetails = null; //Finds the day and fine amount that has been set in the library settings form
    Find out how long the book can be loaned for.
    Code:
    int loanDays = 0;
    loanDays = getLibraryDetails.DaysToBorrow; //Get the days the book can be loaned for - error occurs here
    The error message l get when this code is executed is " Object reference not set to an instance of an object."

    Not sure what l am doing wrong. Hope someone can help

    Thanks in advance,

    Steve
    Last edited by steve_rm; Apr 1st, 2005 at 06:34 AM. Reason: Resolved
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width