/// <summary> /// 动态向comboBox控件的下拉列表添加姓名. /// </summary> /// <param name="cobox">comboBox控件</param> /// <param name="SQLstr">SQL语句</param> /// <param name="n">字段位数</param> public void NameInfo(ComboBox cobox, string SQLstr, int n) { cobox.Items.Clear(); DataClass.MyMeans MyDataClsaa = new TMPT.DataClass.MyMeans(); SqlDataReader MyDR = MyDataClsaa.getcom(SQLstr); if (MyDR.HasRows) { while (MyDR.Read()) { if (MyDR[n].ToString() != "" && MyDR[n].ToString() != null) { cobox.Items.Add(MyDR[n].ToString()); } } } }
/// <summary> /// 动态向comboBox控件的下拉列表添加数据. /// </summary> /// <param name="cobox">comboBox控件</param> /// <param name="TableName">数据表名称</param> public void CoPassData(ComboBox cobox, string TableName) { cobox.Items.Clear(); DataClass.MyMeans MyDataClsaa = new TMPT.DataClass.MyMeans(); SqlDataReader MyDR = MyDataClsaa.getcom("select * from " + TableName); if (MyDR.HasRows) { while (MyDR.Read()) { if (MyDR[1].ToString() != "" && MyDR[1].ToString() != null) { cobox.Items.Add(MyDR[1].ToString()); } } } }