All pastes #279541 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-15 03:18 UTC
rendered paste body
        //-- function used to populate a combo box
        public int PopulateComboBox(ComboBox oComboBox, string sSQL, string sTable, string sValueMember, string sDisplayMember, SqlConnection oConn)
        {
            //-- validate our parameters
			if (oConn.State == ConnectionState.Open)
			{
				//-- create the data adapter object
				SqlDataAdapter myDA = new SqlDataAdapter(sSQL, oConn);
				myDA.TableMappings.Add("Table", sTable);

				//-- create the dataset & dataviewmanager
				DataSet myDS = new DataSet();
				DataViewManager myDV;

				myDA.Fill(myDS);

				myDV = myDS.DefaultViewManager;

				oComboBox.DataSource = myDV;
				oComboBox.ValueMember = sValueMember;
				oComboBox.DisplayMember = sDisplayMember;


				return 0;
			}
			else
			{
				return 1;
			}
        }