1. The first is the establishment of the database tutorial. The code given will cause Chinese garbled characters, so I simply changed it.
First: change varchar (50) to nvarchar (50 );
Second: adds N to the front of each Chinese string
2. Winform program creation, simple interface
The DropDownStyle attribute is changed to DropDownList.
3. Add an application configuration file
Put the database connection part here. When the IP address changes, you only need to change the configuration file, instead of modifying the source program.
4. Code
The code in the winform is not included in the reference of the configuration class and must be manually added.
A class is defined here.
Class ProvinceItem
{
Public string name;
Public int id;
Public string Name
{
Get
{
Return this. name;
}
Set
{
This. name = value;
}
}
Public int Id
{
Get
{
Return this. id;
}
Set
{
This. id = value;
}
}
}
Because the version is 2005, it cannot be abbreviated
Cb saving. items. add (item); in this sentence, an item object is actually added, and the class name is actually returned when the object is converted to the string type. Therefore, you need to modify the attributes of ComboBox for this part: change the DisplayMember attribute value to Name.
Then there is code in cb province
This involves a forced type conversion, which converts the object type to the ProvinceItem type.
5. Running result
We recommend an ajax asp tutorial. net linkage menu code.
Http://down.111cn.net/down/code/net/2011/0612/23159.html