StrataFrame Forum

DBNULL...again

http://forum.strataframe.net/Topic16120.aspx

By Keith Chisarik - 5/4/2008

Scenario:

I have inherited a table with two fields, one decimal, one string. These together represent the primary key. I need both fields on a maintenance form, bound to textboxes.

Display/Edit/Save is working. I cannot get a new record to add.

I get 'Conversion from type 'DBNull' to type 'String' is not valid.' on the line:

Return CType(Me.CurrentRow.Item("ITREPORT"), System.String) in the field properties. I tried to set the defaultValues and the first one sets fine, the second always gives the above error, regardless of the order set. I have PrimaryKeyIsAutoIncremented = False, PrimaryKeyIsUpdateable = True, and even tried out AllowNullsOnNewRow = True. The database fields (DB2) are set to not allow nulls, and have default values set.

I know this could be fixed easily by adding a proper autoincrement key column but I cant, the table is part of a legacy system and the customer is insistant it work as described above, frankly I'm not sure why it isnt. It works fine if the fields are unbound from the textboxes.

I must be missing somethign simple. Which is likely since I havent been coding much lately.

 

By Keith Chisarik - 5/4/2008

I should add I'm on 1.6.5
By Peter Jones - 5/4/2008

Hi Keith,

You could try "Return alternate.." in the BO mapper and set the alternate to "String.Empty".

Do you need to be able to store nulls in that column in database? We don't allow any database column to be nullable unless it is absolutely necessary.

Cheers, Peter

By Keith Chisarik - 5/5/2008

No, both columns are set to disallow NULL. I will try your suggestion now. Thanks.
By Keith Chisarik - 5/5/2008

Is that feature under "Customize" in the mapper? I cant find it elsewhere and for some reason "Customize" and "Clear" are greyed out and the customization wizard bombs out on me. 

NullReferenceException
  Object reference not set to an instance of an object.

Source     : MicroFour StrataFrame AddIns

Stack Trace:
   at MicroFour.StrataFrame.AddIns.DTEprojectsBO.FillProjects(String[] ProjectPaths)
   at MicroFour.StrataFrame.AddIns.PartialClassBuilderCustomizeWizard.ᜀ(ᜏ A_0)
   at MicroFour.StrataFrame.AddIns.PartialClassBuilderCustomizeWizard.ᜀ()
   at MicroFour.StrataFrame.AddIns.PartialClassBuilderCustomizeWizard.OnLoad(EventArgs e)

By Edhy Rijo - 5/5/2008

Keith Chisarik (05/05/2008)
Is that feature under "Customize" in the mapper? I cant find it elsewhere and for some reason "Customize" and "Clear" are greyed out and the customization wizard bombs out on me. 

Hi Keith,

In the BO Mapper, just double click the field you want to modify and on the right side of the Custom Field Properties, set the NULL  Value Option to "Return Alternate on Null" or any other that apply to your case.

By Keith Chisarik - 5/5/2008

Thank you both, that worked!

I'll admit I am confused why that step was necessary, but I'll save that for another day, unless someone is feeling like enlightening Smile

By Edhy Rijo - 5/5/2008

Keith Chisarik (05/05/2008)
I'll admit I am confused why that step was necessary, but I'll save that for another day, unless someone is feeling like enlightening Smile

Well basically that step is there to allow you to handle your specific database Null values, so you can accommodate your SF project to be compatible with any DBNull schema used.  In your particular case you don't have access to modify the database the way you want it, but that will not stop your SF project to keep working.

Just my 0.02 Smile

By Keith Chisarik - 5/5/2008

Makes sense Edhy, thanks.
By Trent L. Taylor - 5/5/2008

I'll admit I am confused why that step was necessary, but I'll save that for another day, unless someone is feeling like enlightening

The solution will prevent the error, but is not the cause of the error.  You actually should not have to do this.  From what I understand, you are creating a new record.  At this point, the database type has no relavance as all of this is intrinsic to the BO.  So it would appear that when you are adding a record the fields are not being initialized...and/or you are referencing this field either through a manual binding, event, or some other code before it gets initialized.

By default, a BO has the AllowNullValuesONnewRow set to false, which forces all rows to be initialized with a default value when a new row is created.  So the NULL is not coming from there...it is happening in the Get of the strong-typed property which means that something is trying to call a GetValue before it is initialized.

You might check your mappings or place a breakpoint in the Get of the property to see what is pulling the value.  You have a "bandaid" on it so to speak and it would probably be a good idea to find the source of the issue.

By Keith Chisarik - 5/5/2008

Will do, I didnt think this step was required since I hadn't done it before, for now I'll take the bandaid but I will try to find the original problem also.
By Trent L. Taylor - 5/5/2008

Sounds good.  I know that something is trying to pull the value on the AddNew or Navigated....something along those lines.  So just to prevent any downstream issues it would definitely be a good idea Smile
By Keith Chisarik - 5/5/2008

1) My banaid broke. I changed the SF Data Store for the project from my SQL Server to my customers as they want to start "helping" and now I cannot set any custom properties on the fields in the mapper, they simply dont "stick". Could this happen if the Strataframe database was not up to date? If so, how can one tell if it is up to date or not? I think it should be but am not 100% sure.

If not, what might be causing this, I need my bandaid back as it is not clear to me what the underlying problem is.

2) Field_ITREPORT_Descriptor is making the call to the get  for Public Property [ITREPORT]() As System.String

By Trent L. Taylor - 5/5/2008

Could this happen if the Strataframe database was not up to date? If so, how can one tell if it is up to date or not? I think it should be but am not 100% sure.

Well, it is possible that your SF database is not up to date, but the issue here is that you created the custom code in Database 1 and are now wanting to work on Database 2.  So that code that was in DB1 is not going to be there.  If you set your data source base to DB1, do you get your stuff back?

That is the first thing I would make sure of.  Then...well...we can try to come up with the best solution for working like this.

By Keith Chisarik - 5/5/2008

Yes if I point back to the original database everything is fine, I did realize that I would have to recreate the project data, it let me redfine the BO's and everything I needed to do EXCEPT the customization. It just ignores and changes I make in the edit customizations screen.

The new database will be the master from now on, I have VPN access to it.

By Trent L. Taylor - 5/5/2008

It sounds like you just did not have the database up to date.  We added a few fields in 1.6.5...so that is probably what you were fighting.
By Keith Chisarik - 5/5/2008

I am still fighting this, no resolution as of yet. I will reinstall 1.6.5 at customer site to make sure the database is updated, unless you can tell me how to check the current version of the Strataframe database?
By Keith Chisarik - 5/5/2008

I see table structure changes between the working and non-working for table "DTEproject_item_exceptions" that seems to hold the customization data. I'll try that in the AM.
By Trent L. Taylor - 5/6/2008

Yeah, this is one of the tables structures that we changed.  Let me know if you don't get it going. Smile
By Keith Chisarik - 5/6/2008

All fixed. Reinstall of 1.6.5 did the trick. Thanks.
By Trent L. Taylor - 5/6/2008

Cool Cool