Forum:  LLBLGen Pro Runtime Framework

Thread:  LLBLGenProDataSource2 not updating w/ empty text box


tprohas (User)   Posted on: 20-May-2008 00:25:55.
LLBLGen 2.5
Runtime: v2.0.50727
ASP.NET 2.0

Hello all,

I have a LLBLGenProDataSource2 control wired up to a DetailsView for editing. The details view pulls up the data and I now want to delete the data from the text box which it's displayed in. The problem is that deleting the text and saving does not change anything. It acts like the empty text box isn't changed so the entity isn't changed or updated when saving.

Can anyone tell me why this is happening? Shouldn't a field which has data deleted from it save as en empty string?
daelmo (Support Team)   Posted on: 20-May-2008 04:45:35.
Hi Aaron, I guess the field isn't nullable and the DetailsView or/and LLBLGenProDataSource2 is sending the value as NULL which isn't a valid value.

Quote:
Shouldn't a field which has data deleted from it save as en empty string?

Yes if you want. For that you should:

1. Tell LLBLGenProDataSource2 that "empty strings" should be treated as "empty strings", not NULL values (Ref: LLBLGenPro Help -> Using the generated code -> Adapter -> Databinding at designtime and runtime -> Databinding with APS.NET 2.0 -> Converting empty string values ("") to NULL values for inserts/updates):
Code:

yourLLBLGenProDataSource.AllFieldsKeepEmptyStringAsValue = true;


or per field basis:
Code:
// in your Page Load handler routine
if( !Page.IsPostBack )
{
    List<string> fieldsWhichShouldKeepEmptyString = new List<string>();
    fieldsWhichShouldKeepEmptyString.Add( "ShipAddress" );
    _ordersDS.FieldNamesKeepEmptyStringAsValue = fieldsWhichShouldKeepEmptyString;
}


2. The grid/detailsView has for every field a property (click on 'Edit fields' in the smarttag of the grid): ConvertEmptyStringToNull. THis is by default set to true. This means that an empty value is send to the datasourcecontrol as null, not as empty string. So the datasourcecontrol receives a null, which means it can't accept it as the field isn't nullable. If you set the property ConvertEmptyStringToNull to false for a textfield which should accept "", an empty textbox will send a "" to the datasourcecontrol, which is then accepted as a value (Ref...).


tprohas (User)   Posted on: 20-May-2008 18:59:36.
So when saving a entity and the entity's field is changed but does not have a value why is the default value used null and not the entity's default field value. Seems like it would be better to have an entity save a field value as that fields default value. In this case the default value for the field being a string.
tprohas (User)   Posted on: 20-May-2008 23:26:44.
Hello daelmo,

I've now tried all three of these methods and I still cannot save an empty text box. Is there anything else I can try?


daelmo (Support Team)   Posted on: 21-May-2008 05:00:23.
You have to do the two steps (1 and 2) I posted.
Anyway, pleas post your actual code: relevant declarative aspx of the DetailsView and LLBLGenProDataSource and any relevant codebehind code.
daelmo (Support Team)   Posted on: 21-May-2008 05:02:00.
tprohas wrote:
So when saving a entity and the entity's field is changed but does not have a value why is the default value used null and not the entity's default field value. Seems like it would be better to have an entity save a field value as that fields default value. In this case the default value for the field being a string.

It's a matter of the GUI controls, not exactly LLBLGen framework.