PredicateExpression

Posts   
 
    
Posts: 54
Joined: 22-Jun-2010
# Posted on: 09-Aug-2010 07:15:58   

LLBLGEN 3.0 Oracle 9i/10g

Hi I am trying to populate state combobox based on city selected. Just have a small glitch whilde doing so. The following code works fine with hardcoded predicatecity.Add(CityFields.CityId==1);

But If change this line as predicatecity.Add(CityFields.CityId==cmbcityid.SelectedValue);. It just does not work. Not able to figure out what is causing the issue

predicatecity.Add(CityFields.CityId==1); bucketstate.PredicateExpression.Add(predicatecity); bucketstate.Relations.Add(StateEntity.Relations.CityEntityUsingStateId); bucketstate.PredicateExpression.Add(StateFields.Flag == StandardFlag.recordvalidflag); adapterstate.FetchEntityCollection(datasourcestate, bucketstate, 0, new SortExpression(StateFields.Description | SortOperator.Ascending)); cmbstateid.DataSource = datasourcestate; cmbstateid.ValueMember = "STATEID"; cmbstateid.DisplayMember = "DECRIPTION"; cmbstateid.SelectedIndex = -1;

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Aug-2010 07:29:57   

Try this:

predicatecity.Add(CityFields.CityId==int.Parse(cmbcityid.SelectedValue));. 
Posts: 54
Joined: 22-Jun-2010
# Posted on: 09-Aug-2010 07:46:15   

Walaa wrote:

Try this:

predicatecity.Add(CityFields.CityId==int.Parse(cmbcityid.SelectedValue));. 

I did try. I get error saying argument type object it not assignable to parameter type string

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Aug-2010 07:51:44   

OK so you have to try this: simple_smile

predicatecity.Add(CityFields.CityId==int.Parse(cmbcityid.SelectedValue.ToString()));. 
Posts: 54
Joined: 22-Jun-2010
# Posted on: 09-Aug-2010 08:07:58   

Walaa wrote:

OK so you have to try this: simple_smile

predicatecity.Add(CityFields.CityId==int.Parse(cmbcityid.SelectedValue.ToString()));. 

This fine But this line also again same issues

filterstate.AddWithAnd(new EntityProperty("CountryName") % "ch%");

Am not able to add combobox in place of "ch%"

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Aug-2010 08:30:18   

Which property of the combo box you want to test against?

Assuming it's the SelectedValue, then you will have to do the following:

var countryName = myComboBox.SelectedValue.ToString() + "%";
filterstate.AddWithAnd(new EntityProperty("CountryName") % countryName);

If it's another property, which is of a string type, then remove the .ToString() from the above code, and use the required property.

Posts: 54
Joined: 22-Jun-2010
# Posted on: 09-Aug-2010 08:36:05   

Walaa wrote:

Which property of the combo box you want to test against?

Assuming it's the SelectedValue, then you will have to do the following:

var countryName = myComboBox.SelectedValue.ToString() + "%";
filterstate.AddWithAnd(new EntityProperty("CountryName") % countryName);

If it's another property, which is of a string type, then remove the .ToString() from the above code, and use the required property.

Thanks this I had tried earlier and it had worked. Thought there might be another way of doing it. Thanks for helping out