Sql select problem ( data fill)

  • Thread starter Thread starter Ricardo Luceac
  • Start date Start date
R

Ricardo Luceac

HI...

I have 2 tables, one for the countries and another for the states, and I
make a fk in the states tables that connect it to the countries table.

But now I want to make a dropdownlist with the countries, and when the
user select the country a listbox will be filled with the states. But
how can I do that??? Is that a way to so a select string int the
dataset??? or I'll need to make another data adapter and make a select
to the database itself???

thx...
 
Hi Ricardo
One thing that you can do is to bind the second combo box ( the one with
the child relation " the state " to a DataView . on that dataview do a
RowFilter on the country name ( depending on the country name displayed on
the first combo box . once the user change that country name , change the
filter to the new country name so that the rows that are available on the
view are only those that are in the new displayed country .
You would have some code like that
private void Country_SelectedIndexChanged(object sender,
System.EventArgs e)
{
dataView_CityRowFilter="countryId="+country.SelectedValue;
}

Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC
 
Hi Ricardo,

I don't know all your DB philosophy, but i can recommend to
use DataView with RowFilter...

dataView1.Table = dataTableAllStates;
If nothing is selected them set
dataView1.RowFilter=String.Empty;
elswere set it as e.g.
dataView1.RowFilter=String.Format("[COUNTRY_NAME]=\'{0}\'"
, comboBox1.SelectedValue);

HTH
Marcin
 
Back
Top