locked
Export to Excel stopped working RRS feed

  • Question

  • I have two screens that display the same datagrid on one the fields are all lables and the second one has some fields set to be editable.

    The second screens export to excel button stopped working in the debugger and I get the following error.

    An error occurred while running the screen. You can close the screen or ignore the error and continue using the screen.
    Error details: Value cannot be null.
    Parameter name: key

    I do not get this error on the other screen but always get it on this screen.

    Sunday, March 8, 2015 4:28 AM

Answers

All replies

  • Hi,

    This is telling you that an entity was retrieved and it has a required field containing a null value. Look at the entities on your queries and find the one you rescently added a new required field to. Updated the database and place a value in this field and this could fix your problem.

    Besides, thread below could also help you:

    https://social.msdn.microsoft.com/Forums/sharepoint/en-US/c96af5c7-bc98-447c-affa-ae2dbc102cfb/error-details-value-cannot-be-null-parameter-name-key?forum=lightswitch

    Best Regards,

    • Marked as answer by reigh7 Monday, March 9, 2015 10:29 PM
    Monday, March 9, 2015 3:21 AM
  • I am able to export the same properties form the same entities using a different screen though? Neither screen has an addition queries the other screen does not have the only difference is that other screen uses labels. I did add an allergies table but it quires the monograms table to get medication names for its table not the other way around. The Monograms table is a simple editable grid related ONE grid to Many Allergies. It has a related property I tried to assign a default to. using the following code oh I see I had to make the entries in my code required even though I am only exporting them. Weird they were old properties I had long ago made and then used code to get around them having to be required.

    It works now cheers

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.LightSwitch;
    namespace LightSwitchApplication
    {
    	public partial class Allergy
    	{
    		partial void AllergySummary_Compute(ref string result)
    		{
    
    			// handle Nulls
    			
    			//make some string vars with defaults
    			string genName = "";
    			string classSum = "";
                string generic = "";
                string classification = "";
    			
    			//set string vars only if Monogram not null
    			if(Monogram != null)
    			{
    				//use null coalesce operator '??' to convert null properties to string
    				genName = Monogram.GenericName ?? "None Listed";
    				classSum = Monogram.ClassificationSummary ?? "No Classification";
                    generic = " / Generic Drug: ";
                    classification = " / ";
    			}
                if (classSum == "")
                    classification = "";
    
    			result = "(Type: " + TypeOfAllergy + generic + genName + classification + classSum + ")";
    		}
    	}
    }

    Monday, March 9, 2015 10:30 PM