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


Author
Message
Ricardo Quartier
Ricardo Quartier
StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 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 (332 views, 77.00 KB)
dbnull_error.gif (334 views, 62.00 KB)
sql_data.gif (303 views, 63.00 KB)
textbox_properties.gif (329 views, 76.00 KB)
Replies
Ricardo Quartier
Ricardo Quartier
StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 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 (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
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.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Ricardo Quartier - 20 Years Ago
Ricardo Quartier - 20 Years Ago
StrataFrame Team - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
             Glad to help ;)
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
             Glad to hear it ;)
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Robert Linton - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
             Got it...thanks.
Trent L. Taylor - 20 Years Ago
Ricardo Quartier - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Edhy Rijo - 19 Years Ago
StrataFrame Team - 19 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search