﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Issues  » Getting error when binding TextBox to field!</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 10:13:13 GMT</lastBuildDate><ttl>20</ttl><item><title>Getting error when binding TextBox to field!</title><link>http://forum.strataframe.net/FindPost9477.aspx</link><description>I have a simple table (Zip codes) which has three fields&lt;br&gt;
ZipCode =&gt; String(7)&lt;br&gt;
State =&gt; String(2)&lt;br&gt;
City =&gt; String(20)&lt;br&gt;
&lt;br&gt;
My primary key is set to ZipCode field.&lt;br&gt;
&lt;br&gt;
I created a maintenance form, placed a copy of ZipCodeBO on the form, placed a "BusineddBindngSource" attached to ZipCodeBO. Placed DataGrid and connected it to BBS.&lt;br&gt;
&lt;br&gt;
I then placed three TextBoxes on the form and connected the them to each field of the table.&lt;br&gt;
&lt;br&gt;
When I run the form and press "New" button, I get the following runtime error.&lt;br&gt;
[quote]  Message="Unable to cast object of type 'System.DBNull' to type 'System.String'."&lt;br&gt;
  Source="BO"&lt;br&gt;
  StackTrace:&lt;br&gt;
       at Playkids.PDS.BO.ZipCodeBO.get_ZipCode() in C:\PDS\Program\BO\ZipCodeBO.Designer.cs:line 283&lt;br&gt;
       at Playkids.PDS.BO.ZipCodeBO.Field_ZipCode_Descriptor.GetValue(Object component) in C:\PDS\Program\BO\ZipCodeBO.Designer.cs:line 485&lt;br&gt;
       at System.Windows.Forms.BindToObject.GetValue()&lt;br&gt;
       at System.Windows.Forms.Binding.PushData(Boolean force)&lt;br&gt;
[/quote]&lt;br&gt;
VS points me to the "Get" section of my ZipCode property.&lt;br&gt;
If I remove the textbox or disconnect the binding, then it works fine.&lt;br&gt;
&lt;br&gt;
I checked the DDT and database, and none the field is checked as "AllowNull".&lt;br&gt;
&lt;br&gt;
Thanks!</description><pubDate>Mon, 11 Jun 2007 14:41:47 GMT</pubDate><dc:creator>Ben Hayat</dc:creator></item><item><title>RE: Getting error when binding TextBox to field!</title><link>http://forum.strataframe.net/FindPost9482.aspx</link><description>Hey Trent;&lt;br&gt;
&lt;br&gt;
[quote]Good to hear from you[/quote]Same here!&lt;br&gt;
&lt;br&gt;
[quote]If you manually initialize the field to an empty string does the error go away?[/quote] Ok, I went to the section "Set default values" and placed:&lt;br&gt;
      this.ZipCode = "";&lt;br&gt;
      this.State = "";&lt;br&gt;
      this.City = "";&lt;br&gt;
And Bingo, solved the problem.&lt;br&gt;
&lt;br&gt;
I'm just curious why this does not happen with other forms?&lt;br&gt;
&lt;br&gt;
I also ran into another issue with DataGrid not following the toolstrip navigation.&lt;br&gt;
This problem appears on all forms. So I must be missing something accross the board.&lt;br&gt;
&lt;br&gt;
If I navigate on the toolbar, the pointer on the grid does not move. Or if I move to the next record on the grid, my textbox field do no get affected.&lt;br&gt;
I'm using BusinessBuinding Source!&lt;br&gt;
&lt;br&gt;
Thank again!</description><pubDate>Mon, 11 Jun 2007 14:41:47 GMT</pubDate><dc:creator>Ben Hayat</dc:creator></item><item><title>RE: Getting error when binding TextBox to field!</title><link>http://forum.strataframe.net/FindPost9478.aspx</link><description>Hey Ben,&lt;/P&gt;&lt;P&gt;Good to hear from you :) Try this to see if the problem at least goes away adn then we can work the other way.&amp;nbsp; The field is being set to DbNull when it is created, by default the BOs will initialize all of the fields unless you set the AllowNullValuesOnNewRow property to False.&amp;nbsp; Then these fields will be NULL which can produce this error.&amp;nbsp; If you manually initialize the field to an empty string does the error go away?</description><pubDate>Mon, 11 Jun 2007 13:56:04 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>