joe_pool_is
Well-known member
I have a DataGridView that successfully populates using our SQL 2000 Server (Using VS 2005).
Whenever the Form loads, I need to populate ComboBox Items with Column options from the EmployeeInfo table.
I have something that runs below, but trying to populate the ComboBoxes throws "Complex DataBinding accepts as a data source either an IList or an IListSource."
What am I doing wrong?
Whenever the Form loads, I need to populate ComboBox Items with Column options from the EmployeeInfo table.
I have something that runs below, but trying to populate the ComboBoxes throws "Complex DataBinding accepts as a data source either an IList or an IListSource."
What am I doing wrong?
Code:
public void DataLoad() {
DataSet ds;
string sqlCmd;
string sqlFmt = "SELECT {0} FROM dbo.EmployeeInfo {1}";
// taEmpInfo is the TableAdapter that links to the DataGridView
SqlConnection conn = taEmpInfo.Connection;
SqlDataAdapter da;
string strErr = "";
try {
ds = new DataSet("EmployeeInfo");
sqlCmd = string.Format(sqlFmt, "*", "Order By [LASTNAME] Asc");
try { // load full list of employees into the DataGridView dgEmpInfo:
da = new SqlDataAdapter(sqlCmd, conn);
da.Fill(dsEmployees, "EmployeeInfo");
dgEmpInfo.DataSource = dsEmployees.Tables["EmployeeInfo"].DefaultView;
} catch (Exception e) {
strErr += "Error Loading the full list:\n" + e.Message + "\n";
}
sqlCmd = string.Format(sqlFmt, "DISTINCT [GROUP]", "Order By [GROUP] Asc");
try { // Fill ComboBox for Groups:
da = new SqlDataAdapter(sqlCmd, conn);
da.Fill(ds, "EmployeeInfo");
cboGroup.DataSource = ds.Tables["EmployeeInfo"].Columns[0];
} catch (Exception e) {
strErr += "Error Loading the groups:\n" + e.Message + "\n";
}
sqlCmd = string.Format(sqlFmt, "DISTINCT [DEPT]", "Order By [DEPT] Asc");
try { // Fill ComboBox for Depts:
da = new SqlDataAdapter(sqlCmd, conn);
da.Fill(ds, "EmployeeInfo");
cboDept.DataSource = ds.Tables["EmployeeInfo"].Columns[0];
} catch (Exception e) {
strErr += "Error Loading the departments:\n" + e.Message + "\n";
}
sqlCmd = string.Format(sqlFmt, "DISTINCT [JOBTITLE]", "Order By [JOBTITLE] Asc");
try { // Fill ComboBox for JobTitles:
da = new SqlDataAdapter(sqlCmd, conn);
da.Fill(ds, "EmployeeInfo");
cboTitle.DataSource = ds.Tables["EmployeeInfo"].Columns[0];
} catch (Exception e) {
strErr += "Error Loading the job titles:\n" + e.Message + "\n";
}
sqlCmd = string.Format(sqlFmt, "[LASTNAME] + , [FIRSTNAME] AS FullName", "WHERE [JOBTITLE]=MANAGER");
try { // Fill ComboBox for Managers (Lastname, Firstname):
da = new SqlDataAdapter(sqlCmd, conn);
da.Fill(ds, "EmployeeInfo");
cboMgr.DataSource = ds.Tables["EmployeeInfo"].Columns[0];
} catch (Exception e) {
strErr += "Error Loading the Managers:\n" + e.Message + "\n";
}
} catch (Exception e) {
strErr += "Error Opening DataSet:\n" + e.Message + "\n";
}
if (strErr != "") {
Console.WriteLine(strErr);
}
}