显示国家,州,城市使用组合框。 [英] display countries,states,cities Using Combo Box.

查看:120
本文介绍了显示国家,州,城市使用组合框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在设计一个 Windows表单应用程序。我拍摄了3个组合框。第一个框显示国家名称。然后选择一个项目在第二个组合框中显示所选国家/地区状态。但我选择状态然后不在第三个组合框中显示城市。我正在使用Sql Server数据库。国家名称作为表名。状态名称作为列名,城市名称作为字段。

所以请给我一些想法来解决这个问题。

Hi,
I am design One windows Form Application. I am Taken 3 Combo Boxes.First Box Display Country names.Then Select one item display selected country states in second combo box.But I am Select State Then Not Display city's in third combo box.i am using Sql Server database. country names taken as table name.state name as column name,city name as fields.
so Please Give Me Some Idea To Solve This Problem.

推荐答案

问题中指定的设计如下所示:

1.每个国家一个表。

2.每个国家/地区表中每个各一列。

3.每个<$ c $一个字段(行) c>每个州的城市。



这个设计很难实施,因为国家数量的任何变化都要求改变数据库中的的编号。同样,国家数量的任何变化都要求改变相应国家表的的数量。 < br $> b $ b

更好的选择是创建三个 国家,州,城市分别为国家,州和城市每行存储一个数据项。



然后对于问题中所述的功能,详细说明的程序以下答案可用于问题中陈述的 Windows Forms Application

组合框用于国家,州和城市。当我选择一个国家/地区时,应对的国家/地区将会显示第二个组合框,当我选择一个国家,coressponing城市将显示... [ ^ ]
The design specified in the question looks like as follows:
1. One table each for each Country.
2. One Column each of each State in each country table.
3. One Field (Row) for each City in each state.

This design is very difficult to implement as any change in No. of Countries requires a change in the No. of Tables in the Database. Similarly any change in the No. of States requires change in the No. of Columns of the corresponding Country table.

A better option is to create three Tables Country, State, City which will store one data item per row for Country, State and City respectively.

Then for the functionality stated in the question, the procedure as detailed in the following answer may be used for Windows Forms Application stated in the question.
3 combobox for country,state and cities.when i select one country that coressponing states will display in 2nd combobox,and when i select one state that coressponing cities will display in...[^]


hi
首先检查状态组合框的事件它必须触发事件。

if如果它触发了一个事件,那么你可以在该事件中编写你的代码如下



private void comboBox2_SelectedIndexChanged(object sender,EventArgs e)

{

SqlConnection conn = new SqlConnection(在这里提供连接字符串);

DataSet ds = new DataSet();

SqlDataAdapter da =新的SqlDataAdapter(select+ state +from+ country,conn);

da.Fill(ds);

ds.Tables [0] 的;这将有一个列,其中包含您选择的州和国家/地区的所有城市数据

}

当您完成此操作后,您可以绑定此ds。使用你的comboBox表格[0]。

注意: - 这里的州和国家是字符串变量,它们是相应下拉列表的选定值

如果你将你的答案标记为已解决得到了答案

谢谢。
hi firstly check for the event of state combobox it must be firing an event.
if if it firing an event then you can write your code in that event as follows

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("provide connection string here");
DataSet ds = new DataSet();
SqlDataAdapter da=new SqlDataAdapter("select " + state + " from " + country, conn);
da.Fill(ds);
ds.Tables[0]; this will have one column which has all the data of cities for the state and country you've selected
}
when you are done with this you can bind this ds.tables[0] with your comboBox.
Note:- state and country here are string variables,and they are selected values of respective dropdowns
Mark your answer as solved if you've got the answer
thanks.


这个早先的问题 [ ^ ]可以为您提供帮助。
This earlier question[^] may help you.


这篇关于显示国家,州,城市使用组合框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆