I'm having some issues with DataReader holding some data from a database.. or at least I think this is how it works.
I have a ComboBox and at the start of the program I populate its Items with data from:
Connect.Open();
Command.Connection = Connect;
Command.CommandText = "Select * from Department";
OleDbDataReader dr;
dr = Command.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
cmbDepartment.Items.Add(dr[0].ToString());
}
}
Connect.Close();
It works fine and populate the ComboBox at the start of the program now when the user selects one item from the combo box.
I would like to have the next ComboBox's Items populate based on what Department the user has selected on the first combo box.
Connect.Open();
Command.CommandText = "select JobTitle from Position where Department ='"+cmbDepartment.Text + "'";
OleDbDataReader dr2;
dr2 = Command.ExecuteReader();
if (dr2.HasRows)
{
while (dr2.Read())
{
cmbPosition.Items.Add(dr2[0]);
}
}
The thing is, I have perfectly similar codes to my classmates and mine has an unusually long error message that we cannot debug.
The error happens after I select something from the cmbDepartment. Using a try/catch, I got this error message:
System.Data.OleDb.OleDbException (0x80004005): IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at katapusan.Employee.cmbDepartment_TextChanged(Object sender, EventArgs e) in c:\Users\Matt\Documents\Visual Studio 2012\Projects\katapusan\katapusan\Employee.cs:line 423