LLBLGenProDataSource2 -- Cannot Update

Posts   
 
    
rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 07-May-2007 22:28:14   

Perhaps we are missing something very obvious... simple_smile

We are using a RadGrid (Telerik Grid) with the LLBLGenProDataSource2 control.

Select is working (grid displays the table). Insert is working (using inline edit of RadGrid, the Insert is working automatically as expected with no surprises). However Update is not working.

No columns are being updated and when enabling SQL trace, there does not appear to be any UPDATE attempt to the DB.

The Grid's UpdateCommand event does fire, and the datasource update parameters collection is empty (I have not set this collection, however I did not need to do this when inserting either. I have also tried adding parameters for a few columns and this did not update either).

I have tried changing the cache location from viewstate to session etc.

How can we get the datasource to update automatically (SELECT and INSERT are working great!)?

Do we have to construct an Entity in the update command and update manually? We have not tried this yet because this should be do-able automatically right?

What do you suggest to solve this update problem?

summary: - using march 21 build llblgen - using llblgenprodatasource2 with RadGrid (telerik grid) - radgrid -> AllowAutomaticUpdates = true - select works - insert works - don't use select/insert parameters because in this test it is working without. - live persistence = true - cache location viewstate and session - SQL trace does not show an update attempt - grid's update command does fire. (not doing any code here)

Thanks!

rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 08-May-2007 11:17:39   

Thanks, this post appeared to be quite similar and I will try the suggestion later:

daelmo wrote:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5653

However, I am still confused about what is possible with the llblgenprodatasource2 control.

Can automatic updates (2-way databinding) be done with this control or must updates be handled manually within the updatecommand of the grid?

Between the "allow automatic updates" of the radgrid and the "live persistence = true" of the llblgenprodatasource2 control, it appears this type of automatic updating should be possible. Inserts and Selects are working automatically now.

I didn't find this clarified in the other posts. It is important that I know what is possible with this control as a lot of tedious DB work will begin shortly. "Plug n Play" behavior for updates as well as the other operations will be great for certain work-flows that need to operate on simple tables.

Thanks!

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 08-May-2007 16:23:33   

Hi,

Yes automatic update is possible with llblgenprodatasource2, I use it everyday wink

rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 09-May-2007 08:53:11   

Apparently, the problem has been found.

If one of the columns in the grid is referencing a varchar value of NULL or '' in the DB, there will be a problem and the update will not occur (this column also has to be referenced in the "DataKeyNames" collection for the RadGrid to produce the issue).

Does anyone know of a solution when a column is varchar == null (allow null is enabled in db column), when doing updates in the grid (RadGrid)?

BTW I tried "FieldNamesKeepEmptyStringAsValue" when changing the DB column value to '' and the same problem exists. It appears '' is being converted to null by the grid at some point?

what do you suggest? I would like null to be a valid value for this column.

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2007 09:00:21   

If you set the field to any value, say "XYZ" would it be updated in the database?

rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 09-May-2007 09:37:37   

Yes, if the field in the DB is set to XYZ, then this will work.

BTW I updated the previous note to add that one more condition must occur to produce the update problem:

The column with the null value must also be listed in the RadGrid's DataKeyNames collection, then the issue will occur.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2007 09:56:56   

I don't have RadGrid, that's why I'm asking these questions:

Now if you type into the cell "XYZ" and then you selected another row, then re-select the "XYZ" cell in the previous row and delete the text.

Now if you save the data, would a null value be saved in the database?

I'm afraid that you were trying to set a field to null where it actually was null, thus the IsChanged was not set to true, and it wasn't issued in the update command.

rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 09-May-2007 12:10:18   

Thanks Walaa,

I cannot test this at the moment, but I am sure you are correct. I would expect the behavior you outlined to be true.

What is the easiest workaround in this case?

Keep in mind that I am actually testing this by editing another column (not the varchar == null column). So shouldn't IsDirty == true since one column has been changed / edited? Why does the null value of another column that is not being edited prevent the SQL update from ever occuring?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2007 17:42:28   

If one of the columns in the grid is referencing a varchar value of NULL or '' in the DB, there will be a problem and the update will not occur (this column also has to be referenced in the "DataKeyNames" collection for the RadGrid to produce the issue).

That's normal, as the DataKeyNames are used as the PK fields used for the Update command (WHERE PK = xxx) and it doesn't take place in the updated set of fields.

If it's not the PK field, then you should remove it from the DataKeyNames.

References: http://msdn2.microsoft.com/en-us/library/ms228051.aspx

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogenerateeditbutton(VS.80).aspx

rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 10-May-2007 11:18:48   

Thank you for your explanation, this is clear now.

I found working with "UpateParameters" and its counterparts has been very effective when needing to add column data to the SQL command, when the columns have not been declared within the grid.

One last question:

If column "fieldA" is declared in the grid and has value 0 during user's update attempt. Then in update/insert command you do llblgendatasource2_1.UpdateParameters.add("fieldA", "1") (or vice versa with InsertParameters on Insert operation), will the new value always over-ride by design?

I tested this and the answer was true (update test). However, I wasn't sure how this is working under the hood and was wondering if duplicate values may break something simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-May-2007 16:04:54   

I'm glad you have worked it out, and thanks for the feedback.