public static void Load(this ComboBox comboBox, string sql, string valueMember, string displayMember)
 {
     using (SqlConnection cnn = new SqlConnection(connString))
     {
         cnn.Open();
         using (SqlDataAdapter sda = new SqlDataAdapater(sql, cnn))
         {
             DataTable dt = new DataTable();
             sda.Fill(dt);
             comboBox.ValueMember   = valueMember;
             comboBox.DisplayMember = displayMember;
             comboBox.DataSource    = dt;
         }
     }
 }
Example #2
0
 public void FillList()
 {
     using (SqlConnection con = new SqlConnection(""))
     {
         var cmd = new SqlCommand("GetData", con);
         var dt  = new DataTable();
         var sda = new SqlDataAdapater(cmd);
         sda.Fill(dt);
         foreach (var row in dt.Rows)
         {
             Kit k = new Kit();
             foreach (var col in dt.Columns)
             {
                 k.GetType().GetProperty(col.Name).SetValue(obj, row[col.Name], null);
             }
             this.Add(k);
         }
     }
 }