Getting error when binding TextBox to field!


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Hey Trent;



Good to hear from you
Same here!



If you manually initialize the field to an empty string does the error go away?
Ok, I went to the section "Set default values" and placed:

this.ZipCode = "";

this.State = "";

this.City = "";

And Bingo, solved the problem.



I'm just curious why this does not happen with other forms?



I also ran into another issue with DataGrid not following the toolstrip navigation.

This problem appears on all forms. So I must be missing something accross the board.



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.

I'm using BusinessBuinding Source!



Thank again!

..ßen
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Hey Ben,

Good to hear from you Smile Try this to see if the problem at least goes away adn then we can work the other way.  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.  Then these fields will be NULL which can produce this error.  If you manually initialize the field to an empty string does the error go away?

Ben Hayat
Ben Hayat
Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)Advanced StrataFrame User (548 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
I have a simple table (Zip codes) which has three fields

ZipCode => String(7)

State => String(2)

City => String(20)



My primary key is set to ZipCode field.



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.



I then placed three TextBoxes on the form and connected the them to each field of the table.



When I run the form and press "New" button, I get the following runtime error.

Message="Unable to cast object of type 'System.DBNull' to type 'System.String'."

Source="BO"

StackTrace:

at Playkids.PDS.BO.ZipCodeBO.get_ZipCode() in C:\PDS\Program\BO\ZipCodeBO.Designer.cs:line 283

at Playkids.PDS.BO.ZipCodeBO.Field_ZipCode_Descriptor.GetValue(Object component) in C:\PDS\Program\BO\ZipCodeBO.Designer.cs:line 485

at System.Windows.Forms.BindToObject.GetValue()

at System.Windows.Forms.Binding.PushData(Boolean force)



VS points me to the "Get" section of my ZipCode property.

If I remove the textbox or disconnect the binding, then it works fine.



I checked the DDT and database, and none the field is checked as "AllowNull".



Thanks!

..ßen
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search