Conversion from type 'DBNull' to type 'String' is not valid.


Author
Message
Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Hello.. this is what I am doing now... Im trying to pupulate the combo box, but i'm gettin this error "Conversion from type 'DBNull' to type 'String' is not valid.". The funny thing is that I have a a text box that loads from the same BO and loads the same field, and it's working..

PS - I dont have any null info on the "nome_clube" field on the table.

Any Clues.. anyone?

Attachments
combobox_properties.gif (245 views, 77.00 KB)
dbnull_error.gif (240 views, 62.00 KB)
sql_data.gif (213 views, 63.00 KB)
textbox_properties.gif (232 views, 76.00 KB)
Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)
Group: Forum Members
Posts: 87, Visits: 779
I forgot to say thanks in advance.. BigGrin
StrataFrame Team
S
StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Hello Ricardo,



Your problem is not because you have a NULL field in your data, the problem is that there is no data in the combo box to copy back into the field (it's throwing the error on SetValue(), not GetValue()). So, I assume that since you're not populating the combobox through StrataFrame you must be populating it manually. In this case, it's probably being bound before getting populated.



If you're populating in the Load event of the form, then move your code that populates the combobox to the ParentFormLoading event of the combobox to ensure that it gets populated before binding to the business object.
Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Hello Ben, please is this right?

Public Class frmCadClubes

Private Sub ClubesBO1_ParentFormLoading() Handles ClubesBO1.ParentFormLoading

Me.ClubesBO1.FillTop100()

End Sub

Private Sub ComboBox1_ParentFormLoading() Handles ComboBox1.ParentFormLoading

Me.ClubesBO1.FillTop100()

End Sub

End Class

Im not sure, if Im doing right, because Im getting the same error... please help .. thanks


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
Ricardo,

Since you are trying to popualte a combo from a business object, you should use the PopulateionDataSourceSettinngs on the combo box itself.  Also you will need to change the population method from manual to BusinessObject on the combo box also.  The code sample you showed above is actually not going to work for two reasons.  First, you are populating the business object twice.  Once in the ParentFormLoading of the combo box and again in the load of the business object itself. 

Secondly, the reason you are still getting the error is because the DataSource, DisplayMember, and ValueMember of the combo box were never set which tells the combo how to populate and interact with the bound data.  So you need to do one of two things:

Manual Population
1. Remove the Me.ClubesBO1.FillTop100() from the ParentFormLoading event of the business object itself.  Leave the other in the combo boxes ParentFormLoading.
2. Make the combo box ParentFormLoading event look like this:

Private Sub ComboBox1_ParentFormLoading() Handles ComboBox1.ParentFormLoading

Me.ClubesBO1.FillTop100()

'-- Set the display member
Me.ComboBox1.DisplayMember = "[MyDisplayFieldName]"
Me.ComboBox1.ValueMember = "[MyValueMemberField - Usually a Primary Key Field]"
Me.ComboBox1.DataSource = Me.ClubesBO1.CurrentDataTable

End Sub

End Class

Replace the display and value member fields with the names of the fields you wish to use.

Better Solution - PopulationDataSourceSettings
1. Remove all of calls to ClubesBO1.FillTop100 from all methods.
2. Through the form designer, navigate to the combo box.
3. In the property sheet, navigate to the PopulationDataSourceSettings
4. Click the "..." button to the right of the value
5. When the editor appears, set the Business Object Type to "ClubesBO"
6. Set the Method to Execute to "FillTop100()"
7. Add the fields that you wish to have displayed in the combo box at the bottom left of the editor
8. To tell the combo box how to use those selected display fields, set the Display Member Format String.  For example, if you only added a single display member field, the format string will look like this: {0}
9. Pick the value Member field.  This is the fields that will be bound to the data.
10. Click OK.
11. Set the PopulationType property on the combo box to Business Object.
12. Save your changes and run the form.  This should get you going. Wink

Let me know if you have any questions.

Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Awesome ! Thanks, Trent !
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
Glad to help Wink
Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Hi, Trent... me again.. now I can load comboboxes on all forms.. that makes me very happy... but can u please teach me how to save the data from a diferent table to the first?

Example: I have a form 1 to insert data from Clubs (soccer), then i load all the textboxes, from the table called (tb_clube), to insert, edit.. and been filled by a BO called "clubeBO", all okidoki like the example you guys made on the tutorial.

Then I inserted a new BO called "paisBO" (means country), and made the same fill method. If i put a combobox to load like u teach me, it brings all the countries... But the thing is that I want to insert on the clubs form this countries comboBox, to load the data from the coutries table and insert the value field (a primary key called pais_id_cod) on the country field on the clubs table.. and somehow, when i navigate the records, see the country that belongs to that team... instead of the value.... like 1, 2, 3....

Am I been anoying? BigGrin, not sure if it's even possible... but i guess it is... not sure how with strataframe... either...

If u got time, and nothing better to it... please drop a few lines.. (of code too) Cool

Best Regards...

Ricardo

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
Just to verify what you are attempting to do before I send you some code.  You have a combo box that you want to populate with the countries which is bound to a field in the clubs table, correct?  But when you bind and navigate right now it is showing a number (i.e. Primary Key or something) rather than the country description.  Also, I assume that your country database has a primary key and that primary key is tied to the clubs country field, correct?

Country Table                      Club Table
Primary Key - Integer  ----- ClubCountry - Integer
Description - String

The simple table above is just to verify that I understand your data structure and what you are attempting to do.  Please advise and let me know if I understand your situation.  Thanks.

Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)StrataFrame Novice (113 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Hi everything u said was correct, but i still did not inserted the clubs combobox in the clubs form, but.. it was going to show the number of the country (PK) coming from the countries table..  i guess

So, u got it...

Thanks ....

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