The third-party control solves this problem: After a combox is bound with a name and ID, it may cause an issue to get the ID. You need to set the manual deletion and add the selectedindexchanged event.
Code:
Private void Tc () // combox binding name
{
Sqlconnection con = new sqlconnection (****);
Sqldataadapter ad = new sqldataadapter ("select typeid, typename from typeB select stateid, statename from Stateb", con );
// Sqlcommand sqlcom = new sqlcommand ("select typeid, typename from typeB select stateid, statename from Stateb", con );
Dataset DS = new dataset ();
// Datatable dt = new datatable ();
Ad. Fill (DS );
// Ad. Fill (DT );
// SHz = new int [Ds. Tables [0]. Rows. Count];
// For (I = 0; I <Ds. Tables [0]. Rows. Count; I ++)
//{
// Comboboxex2.items. Add (Ds. Tables [0]. Rows [I] [1]);
// SHz [I] = convert. toint32 (Ds. tables [0]. rows [I] [0]); // It is called when an ID is used later. It cannot be displayed here.
//}
// Shz1 = new int [Ds. Tables [1]. Rows. Count];
// For (I = 0; I <Ds. Tables [1]. Rows. Count; I ++)
//{
// Comboboxex1.items. Add (Ds. Tables [1]. Rows [I] [1]);
// Shz1 [I] = convert. toint32 (Ds. Tables [1]. Rows [I] [0]);
//}
Comboboxex1.datasource = Ds. Tables [0];
Comboboxex1.displaymember = "typename ";
Comboboxex1.valuemember = "typeid ";
Combobox1.selectedindexchanged-= new eventhandler (combobox?selectedindexchanged); // manually delete the selectedindexchanged event
Combobox1.datasource = Ds. Tables [0];
Combobox1.displaymember = "typename ";
Combobox1.valuemember = "typeid ";
Combobox1.selectedindexchanged + = new eventhandler (combobox?selectedindexchanged); // manually add the selectedindexchanged event
// Manually delete and add, and then obtain its ID. Otherwise, an error is returned... Third-party controls solve this problem and can be compared and learned.
}
Private void comboboxex1_selectedindexchanged (Object sender, eventargs E)
{
// Typid = sHz [comboboxex1.selectedindex]; // The obtained ID. When the SQL statement has where id = '+ typid + "'
Typid = convert. toint32 (comboboxex1.selectedvalue );
}
Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
Typid1 = convert. toint32 (combobox1.selectedvalue );
}