- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
setting update parameters in a gridview
Joined: 25-Nov-2007
This is probably more of a Windows webform issue or an Oracle database (primary keys) issue, but I am going in circles and hope you can help with a basic update problem.
I am using LLBLGenPro 2.6 Final, June 6, 2008 and Visual Studio 2005 NET 2.0 (2.0.50727 SP2) with C# and an Oracle 10g database. I am using SD.Presets.Adapter.General2005.
I have successfully used filters and displayed read only data in a gridview, but now I would like to implement editing the rows of the gridview. In the gridview smart tag, I checked "edit" to be displayed as a button. I do get the "update" "cancel" options when clicking on "edit", but when I enter new text in the field, it doesn't get updated. Well, at first it didn't get updated at all/data stayed the same. Now when I edit a field it turns to an empty string. At least I'm getting to the database and changing something.
I set up the datasource, testing with a single table as an Entity, although I would like to move to editing a view saved as an Entity if that is possible. But for now I am just trying to update one table.
I am using LivePersistence = "true" and have added fields to the "Update Parameters" in the properties of the datasource. I also set the field I would like to update as a template field.
Originally I had problems with "no primary key fields specified in the bound control". I went back to LLBLGenPro and set a unique student Id as a primary key. In the database, there are two primary keys defined, one a unique row id and the other a unique student Id. In LLBLGen I set the student Id as the Primary Key. For the row id, should I check the box for it to be set as a "sequence"? Do I need both these set as PK?
For the GridView I have:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" DataSourceID="_studentDS" DataKeyNames="StRidPk,StCepStudentId" ForeColor="#333333" GridLines="None" AllowSorting="True">
I'm guessing I am not correctly setting the Update Parameters or need to add code to the .cs file, but I haven't been able to find an example of this (updating a row of a gridview).
For the DataSource I have tried different syntax for UpdateParameters, including:
<llblgenpro:llblgenprodatasource2 id="_studentDS" runat="server" adaptertypename="cep.DatabaseSpecific.DataAccessAdapter, cepDBSpecific" datacontainertype="EntityCollection" entityfactorytypename="cep.FactoryClasses.CepStudentsTbEntityFactory, cep"> <UpdateParameters> <asp:ControlParameter ControlID="GridView1" Name="newparameter" PropertyName="SelectedValue" Type="String" /> </UpdateParameters> </llblgenpro:llblgenprodatasource2>
Thanks for any pointers, Carol
Hi Carol,
There are few things you should check:
- Check that these fields indeed the primary key fields, and that those exist and are written in the correct casing:
DataKeyNames="StRidPk,StCepStudentId"
- In your updateParameters, you are asking for a "SelectedValue" on the GridView. The GridView doesn't have such property AFAIK. Normally this is a Session value or a control value, something like:
<UpdateParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CustomerId"
PropertyName="SelectedValue" Type="String" />
</UpdateParameters>
- After checking above points, take a look at the generated sql to see what really is going wrong.
If the problem persist please attach the complete relevant declarative code (aspx) and your LLBLGen runtime library version (http://llblgen.com/tinyforum/Messages.aspx?ThreadID=7720).
Joined: 25-Nov-2007
Hello Daelmo, Thanks for your helpful suggestions. The key fields may be the problem. I have one, the "StCepStudentId" specified as a PK in LLBLGenPro (and in the database) but the second is not indicated as a PK in LLBLGenPro, but it is part of the PK in the database. "StRidPk" is a generated number in Oracle. (I have a trigger and a sequence set to add a row id in the database when a new record is added.) In LLBLGenPro, I wasn't able to set it as a PK, but I did see a place to check "sequence". I can check with the Oracle DBAs to see if perhaps I can change the PK to just one value, if this is desirable. I'm not sure just where to cast the row ID as a number, but I'll look further at examples.
In your updateParameters, you are asking for a "SelectedValue" on the GridView. The GridView doesn't have such property AFAIK. Normally this is a Session value or a control value
You are right here, I was grabbing an example from the documentation about live persistence set to true to test things. Again, I'll look further to see just how I should set these paramenters. That is, how to enter the specific values for the System.Web.UI.WebControls.ParameterCollection. I see that you can add update paramenters in the designer of the datasource control, but I'm not sure just what to put for the name and value and what, if anything to put for the source (Session, Control, Form, etc.) I will also follow up with configuring my application so that I can view the generated sql. Something is happening, as the value I'm trying to update gets set to null. I'm going to be away from my database for a couple of weeks, until January 7, as we close down for the holiday break. But I'll likely be back with more questions! Thanks, Carol
cgray wrote:
Hello Daelmo, Thanks for your helpful suggestions. The key fields may be the problem. I have one, the "StCepStudentId" specified as a PK in LLBLGenPro (and in the database) but the second is not indicated as a PK in LLBLGenPro, but it is part of the PK in the database. "StRidPk" is a generated number in Oracle. (I have a trigger and a sequence set to add a row id in the database when a new record is added.) In LLBLGenPro, I wasn't able to set it as a PK, but I did see a place to check "sequence". I can check with the Oracle DBAs to see if perhaps I can change the PK to just one value, if this is desirable. I'm not sure just where to cast the row ID as a number, but I'll look further at examples.
That's weird. If you indeed have two fields in your PK, they should appear as "part of primary key" in LLBLGen Designer. So I think you should refresh the catalog at LLBLGen Designer and then regenerate code.
cgray wrote:
In your updateParameters, you are asking for a "SelectedValue" on the GridView. The GridView doesn't have such property AFAIK. Normally this is a Session value or a control value
You are right here, I was grabbing an example from the documentation about live persistence set to true to test things. Again, I'll look further to see just how I should set these paramenters. That is, how to enter the specific values for the System.Web.UI.WebControls.ParameterCollection. I see that you can add update paramenters in the designer of the datasource control, but I'm not sure just what to put for the name and value and what, if anything to put for the source (Session, Control, Form, etc.)
Yes. You should decide from where you are passing the value to the updateParameters. If you just want to pass one value in all cases, you can do that outside the updateParameters (at entity initialization for instance).
cgray wrote:
I will also follow up with configuring my application so that I can view the generated sql. Something is happening, as the value I'm trying to update gets set to null.
Ok, It's very easy, if you need further help, let us know.
cgray wrote:
I'm going to be away from my database for a couple of weeks, until January 7, as we close down for the holiday break. But I'll likely be back with more questions! Thanks, Carol
Happy vacations/holidays!
Joined: 25-Nov-2007
In the last couple of days I finally have updates in a GridView working (mostly).
I went back and refreshed the catalog and regenerated the code. I am now able to see the check box for 'Is part of primary key' for the Row Id field. I checked this for the table I am updating and the update works fine.
However, I still have a problem when trying to use a view that is configured as an entity. The error I get is "ORA-01779: cannot modify a column which maps to a non key-preserved table". I will look into this further, and try and set up a view which will update. (This seems to be a database issue, with key restraints on the view, not a problem with the generated code.)
So I changed my approach and am using a master/details set of grids. I use the first grid for selecting the student whose contact information is to be updated and the details grid uses one table, with contact information, and the primary keys are defined.
For the datasource for the details page, I use _studentContactInfoDS as the data source. I have no idea if this (below) is the normal way to do this, but it works!
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) {
_studentContactInfoDS.FilterToUse = new RelationPredicateBucket(CepContactInfoTbFields.CtCepStudentIdFk == GridView1.SelectedValue);
}
A couple of remaining questions. As well as checking the box for 'Is part of primary key' should I also be checking 'Is Identity /Sequence field' for the Row Id field, which is a generated sequence in Oracle? I tried both checking it and not, and could not see any difference. Perhaps this is only needed when adding a new record?
And lastly, should I be using a prefetch path? I see this mentioned primarily with Self-Servicing, and I'm using Adapter. However, if that is the way to go I'll look at adding a prefetch path to my Page_Load.
Thanks again for the helpful suggestions. I finally feel as though I'm making real progress. Carol
Joined: 08-Oct-2008
The checkbox should only make a difference for new records as it tells the code how to correctly interact with the database to fetch the newly generated key value.
PreFetch paths are used to fetch a related entity or collection of entities for the entity in question - the classic example being a customer and their related orders. The pre-fetch path is to specify that you want to fetch the orders at the same time.
Using Adapter, PreFetch paths are the ONLY way to fetch related collections at the same time that the entity is fetched as Adapter does not use lazy loading. What related information do you need to fetch with your student collection ?
Matt
Joined: 25-Nov-2007
Hello Matt, I also want to do something fairly common. We have a main table of students with their core personal data, such as name and birth date and other attributes. A second table holds address and other contact information. In this case, I want someone to be able to select as student, based on their name and unique student ID, and then retrieve the contact information for editing.
At times there will be other related tables that I would like to fetch as well, such as school enrollment, ethnicity details, and academic activities. There are six main tables frequently used, although not all at the same time. The database complexity is what led me to initially using views to display combined data.
Thanks, Carol
Welcome back Carol,
If you will edit the fetched data, then using entity collections is preferred, as views are read only. You also can use your view to populate the results and when the user click "edit" then you fetch the involved entity, that entity is the one you will edit/save.
Joined: 25-Nov-2007
Thanks, and is it nice to finally have things working!
I'll look further into doing as you suggest, with views displaying data and then fetching the entity to update. With the contact information, I'm using one entity as a datasource to both populate and update the database by way of a details grid.
Somewhere I thought that if a view was configured as an entity in LLBLGenPro that an update could happen through a view. But now that it works so easily as a separate update grid, I'm going to look further into using related entities.
I have also finally got multiple filters working together, and will spend more time on this documentation. It is very cool how easily things work once I figure out some of these basics.
Lastly, it looks like I should be using a PreFetch path, so I'll also look into adding this. Often the updates go very quickly, but sometimes thing seem to grind to a halt.
Thanks for the help, Carol