locked
Problem with adding a parameterized query RRS feed

  • Question

  • I have an existing editable grid screen for Clients and I wanted to create a new data/edit screen along the lines of the Beth Massi video.

    I created the new data screen and then added the new screen entity for the parameter and then added the query and set the data binding for the query parameter to the screen parameter. 

    Everything worked fine until I tried adding a new record whereupon I recieved a program halt saying that the ClientID property could not be altered because it was read only. 

    The clientID  is the name I gave to the screen property used as the parameter to the screen but I never specified that the ClientID field was read only.  

    So I changed the screen parameter to a different name (Client_ID instead of ClientID) and then bound it to the query parameter but I still received the same program halt saying that ClientID is read only.

    I then thought that perhaps because I had an existing editable Grid screen that had the same field name for the Client ID field as I had used for the screen parameter in my new screen (before I changed it from CLientID to Client_ID) that somehow was causing a problem so I deleted the editable grid screen, rebuilt the project, and then tried adding a new client again and again I got the same error saying that ClientID was read only.   

    The error was in the following section of code, but I had already restored the project from backup before I took the following snapshot of the code, which is why you don't see the property for read only.

    <EntityType

        Name="CLIENT">

        <EntityType.Attributes>

          <DisplayName

            Value="Clients" />

          <DefaultScreen

            Value="LightSwitchApplication:CLIENTDetail">

            <DefaultScreen.Attributes>

              <ScreenParameterMapping

                KeyProperty="CLIENT/Properties[ClientID]"

                ScreenParameter="LightSwitchApplication:CLIENTDetail/Properties[CLIENTClientID]" />

            </DefaultScreen.Attributes>

          </DefaultScreen>

        </EntityType.Attributes>

        <EntityType.Methods>

          <EntityMethod

    So my question is... why?

    Why did the system keep indicating that the ClientID field was read only even after I removed the screen that had defined the field as type "A". 

    Thanks

       

     
    • Edited by Jyuma1 Wednesday, January 23, 2013 5:10 PM
    Wednesday, January 23, 2013 5:09 PM

Answers

  • I found the problem.  There is joy in Mudville again.

    The problem was in the entity designer... well, the problem was in me but I introduced it to the program through the entity designer. 

    Don't use  fieldname.ToUpper on a field that is the key to the table, it will throw an IsReadOnly error on an update function.  Boy do I feel dumb.

    Thanks

    P.S.  In my defense, the ToUpper worked when the LightSwitch generated screens were used for entry and update but threw an error when my custom screen was used.  I don't know why.  

     

    • Marked as answer by Jyuma1 Wednesday, January 23, 2013 9:54 PM
    Wednesday, January 23, 2013 9:54 PM

All replies

  • The problem is back.

    The error is shown on the last line of the following image (Just before end set/ end property):

    Wednesday, January 23, 2013 6:25 PM
  • I removed every screen from the project that touches the ClientId and then rebuilt the project.

    I closed LS and then reopened it and viewed the code.  I found this in the code...

    <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _

            Partial Private Sub ClientID_IsReadOnly(ByRef result As Boolean)

            End Sub

    I'm lost.  :(


    • Edited by Jyuma1 Wednesday, January 23, 2013 6:47 PM
    Wednesday, January 23, 2013 6:46 PM
  • I searched though the code again this time looking for IsReadOnly and I found that all the fields have an IsReadOnly attribute that is Boolean so I assume that the IsReadOnly can be dynamically set in code... therefore, something is setting ClientId to IsReadOnly and it is not being reset by whatever it is that is supposed to reset it.

    I'm still lost so please... anybody who knows what's going on please feel free to jump right in. :)

    It's looking more and more to me that it is unlikely that Lightswitch could be successfully used by anyone without fairly extensive knowledge in VB or C# programming. That's not necessarily a bad thing... only quite different from what I had originally thought.

    Thanks

     
    Wednesday, January 23, 2013 7:33 PM
  • Additional information:

    After deleting all screens that display, create or update client records I created a new Search Data screen using the client table as input. That's all I did... I did not create a details or a new data screen.

    I ran the client search screen and a list of all the clients came up. I clicked on one of the clients and the Lightswitch generated edit screen came up. I was able to edit and save the record without any problems.

    I then returned to the search clients screen and selected the add button (I had created the add button when I created the screen but did not override the code). The Lightswitch generated add screen came up and I was able to create and save a new record without any problems.

    I then followed the Beth Massi video for creating a screen that can both add and edit records. I named the screen parameter ClientParm and I named the Query ClientQuery. I also made the required changes to the InitilizeDataWorkspace, the Default client screen and the Button code on the Search Data screen. This time when I clicked on an existing client and changed data and tried to save the changes I got the error about ClientID being ReadOnly. Ditto on the create new record. I am not touching the ClientID field at all and I did not use the field as my screen parm and yet the system throws and error about ClientID being read only but only if I try to make an New/Edit screen.

    Now I'm really lost. :(

         

    Wednesday, January 23, 2013 8:30 PM
  • I found the problem.  There is joy in Mudville again.

    The problem was in the entity designer... well, the problem was in me but I introduced it to the program through the entity designer. 

    Don't use  fieldname.ToUpper on a field that is the key to the table, it will throw an IsReadOnly error on an update function.  Boy do I feel dumb.

    Thanks

    P.S.  In my defense, the ToUpper worked when the LightSwitch generated screens were used for entry and update but threw an error when my custom screen was used.  I don't know why.  

     

    • Marked as answer by Jyuma1 Wednesday, January 23, 2013 9:54 PM
    Wednesday, January 23, 2013 9:54 PM
  • Ed, I can't put my finger on what it is, but you're doing something wrong. What you've described is a simple & easy scenario that should not involve any special coding.

    If you want to send me a zipped copy of the project that exhibits the problem, I'll have a look at what's wrong (I'll probably see it quite quickly).

    You already have my email address.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    Thursday, January 24, 2013 3:14 AM
    Moderator
  • Yann, I'm assuming that by placing code in the program that proports to unconditionally change the key to upper case is what the system was complaining about at execution time.

    Perhaps I should have qualified the code to only switch to upper case on a new record and not an existing record.  If I force the field to upper case on "New" then it could never be lower case on update.

     

      
    Thursday, January 24, 2013 12:52 PM