public static void cboTypesInit(ComboBox cboTypes) { cboTypes.Items.Clear(); DBHelper db = new DBHelper(); string sql = "select * from types"; try { DbCommand cmd = db.GetSqlStringCommand(sql); using (DbDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { VirtualTrain.model.Type type = new VirtualTrain.model.Type(); type.id = (int)reader["id"]; type.name = (string)reader["name"]; cboTypes.Items.Add(type); } } } catch (Exception e) { throw e; } }
//private void cboDifficultiesInit() //{ //cboDifficulties.Items.Clear(); //ArrayList list = new ArrayList(); //DBHelper db = new DBHelper(); //string sql = "select distinct difficulty from questions"; //try //{ // DbCommand cmd = db.GetSqlStringCommand(sql); // using (DbDataReader reader = db.ExecuteReader(cmd)) // { // while (reader.Read()) // { // list.Add((string)reader["difficulty"]); // } // } // cboDifficulties.Items.AddRange((string[])list.ToArray(typeof(string))); //} //catch (Exception e) //{ // throw e; //} //} //获得类型的id public static int getTypeId(ComboBox comboBox) { object item = comboBox.SelectedItem; if (item != null) { VirtualTrain.model.Type type = item as VirtualTrain.model.Type; return(type.id); } else { return(-1); } }