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


Author
Message
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,

This will work similar as the example I showed you previously.  Follow the steps below:

1. Select the country combo box
2. Click the PopulationDataSourceSettings
3. Choose the Country Business Object
4. Choose the method that will Fill the BO with the countries
5. Add the country name as the display column
6. Add {0} to the format column
7. Pick the primary key of the Country table for the Value Member
8. Click OK
9. Make sure that the PopulationType of the combo is set to BusinessObject
10. On the same combo box, select the BusinessObject property to the instance of the Clubes on the form
11. Set the BindingField to the Country field in the Clubes table.

That should be it.  Let me know if you have any questions.

Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Yo Trent, all okidoki. Thanks

Now i have 3 combos... Contry, State and City

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 hear it Wink
Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Yo, last "question" and a diferent help BigGrin

Now I have those 3 combos, like i said before, the thing is that they are not really "very" dependent. So this way I can chooseto set a club on any country (this is allright) but then when i drop down the states, it shows the states of all countries, anyway, this one is agressive, when i drop down the cities, it show thousands of cities from all around the world. w00t

My database is kind simple (4 tables right now)

Clubs
-------
clubId
countryId
stateId
cityId

Contries
--------
countryId
description

State
-------
stateId
description

Cities
-------
cityId
description

Is there any way of strataframe to handle this, "make then dependent"? I use to do this on aspx pages.. using a comand on a query, that concatenate the sql and the value of the parent combo, like:

"select * from states where country = ' & cboCountries.selectedvalue = 25 & '"

Something like that... then i put the code on the event change of the combo and on the form load to bring right the first record.

Any great clues? a "how to" will be great, i won't lie (if that does not take so much time from u).

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
Right now you are populating each combo box using all rows in the respective table.  This will obviously not work very well for tables with a lot of records.  You only need to show the cities that belong to state when populating the cities combo, and then you need to only load the available states for the selected country.

I assume that your database knows these relationships.  I am going to talk about the city combo, but the same will apply to the states.  In your table, your city data structure should know the state to which it belongs.  So you would need to create a Fill method on the BO that looks something like this:

Public Sub FillCityByState(Byval StatePrimaryKey As Integer)
     Me.FillDataTable("SELECT * FROM cities WHERE city_state = " & StatePrimaryKey.ToString())
End Sub

Next, you will want to change the PopulationDataSourceSettings of the city combo to use the above method.  The one thing that you need to is specify the parameter StatePrimaryKey when the combo loads.  To do this, capture the ListPopulating event on the city combo box.  Inside that event, place code similar to this:

e.Parameters(0).Value = MyStates.State_PrimaryKey

Now you need to tell the city combo to reload when the state changes.  So in the SelectedValueChanged or the SelectedIndexChanged event of the State combo box, place the following code:

MyCityCombo.Requery()

This will force the cities to repopulate based on the new state selection.

Once last thing you can do to make sure that the object populate in the correct order since they rely on one another, is set the InitializationPriority.  This will ensure that order they are loaded when instantiating the form will happen in the proper order.  Place a value like this on each combo:

Country Combo Initialization Priority: 25
State Combo Initialization Priority: 26
City Combo Initialization Priority: 27

Let me know if you have any questions.

Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Yo Trent, this line:

e.Parameters(0).Value = MyStates.State_PrimaryKey

I inserted here: (note - cboCidade is my combo of cities)

Private Sub cboCidade_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles cboCidade.ListPopulating

e.Parameters(0).Value = MyStates.State_PrimaryKey

End Sub

It keeps giving this error: (Name 'MyStates' is not declared.) should it be one of my controls ? One of the comboboxes? CityBO?


Robert Linton
Robert Linton
StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)StrataFrame Beginner (15 reputation)
Group: Forum Members
Posts: 13, Visits: 49
 Hi Ricardo,

"MyStates" is used as an example, you will want to substitute that with the name of the StateBO in your code. The line,  e.Parameters(0).Value = YourStateBO.State_PrimaryKey is getting the current primary key from the State BO and assigning it to the query parameter.

Hope that helps,

Rob


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
Rob is exactly right, I really don't have anything to add.  Let me know if you need more detail. Wink
Ricardo Quartier
Ricardo Quartier
StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)StrataFrame Novice (107 reputation)
Group: Forum Members
Posts: 87, Visits: 779
Thanks Rob that helped me to understand, but im still gettin' an error when i try to run... (so i must done something worng i guess)

This is what i done so far:

1 - On my cities BO, called (CidadesBO)

Public Sub FillCityByState(ByVal StatePrimaryKey As Integer)
        Me.FillDataTable("SELECT * FROM tb_cidade WHERE cidade_estado_id = " & EstadosBO.EstadosBOFieldNames.estado_id_cod.ToString())

'ESTADOSBO is the BO of states
End Sub

2 - On the Clubs form, called (frmCadClubes)

2.1 - City Combo

Private Sub cboCidade_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) Handles cboCidade.ListPopulating
        e.Parameters(0).Value = EstadosBO.EstadosBOFieldNames.estado_id_cod

'ESTADOSBO is the BO of states
End Sub

2.2 - State Combo

Private Sub cboEstado_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboEstado.SelectedValueChanged
        cboCidade.Requery()
End Sub

3 - I set the the Initialization as you told me.

But when i run, the code stops on this "requery line" and gives this message:

{"Invalid column name 'estado_id_cod'."} but this is the primary key of the table states, and that repeats on the field called "cidade_estado_id" on the cities table, so this is the link.

On the pic Im sending a diagram w00t maybe give some clue.

Please be patience BigGrin

Attachments
diagram.gif (134 views, 60.00 KB)
error.gif (137 views, 67.00 KB)
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,

Your fill method is wrong on the cities.  Try this instead:

Public Sub FillCityByState(ByVal StatePrimaryKey As Integer)
        Me.FillDataTable("SELECT * FROM tb_cidade WHERE cidade_estado_id = " & StatePrimaryKey.ToString())

The code you had referenced its own property which was causing the error you described.  Try this and let me know how it goes. Cool

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