The 'OleDbException' says that the problem is a 'Type mismatch in expression.', but I've checked in the database (access) and the combobox, and both are string type.
I've tried making the combobox as string with comboBox_CourseID.SelectedItem.ToString()
and changing to comboBox_CourseID.Text
, but still the same exact error. I've also tried checking the type of column in Access, but it was Short Text.
I've tried using a textbox instead of a combobox, but to no success.
This is my code:
OleDbCommand show_table = new OleDbCommand
{
Connection = connect,
CommandText = "Select Student.StudentID, Student.First_Name, Student.Last_Name, Student.Contact_Number, Student.Email " +
"From Student Inner Join Course on Course.CourseID = Student.CourseID " +
"Where Course.CourseID = '" + comboBox_CourseID.SelectedItem.ToString() + "'"
};
OleDbDataReader dataReader =show_table.ExecuteReader();
*//error here*
if (dataReader.Read() == false)
MessageBox.Show("Record Not Found.");
dataReader.Close();
OleDbDataAdapter displayCourseID = new OleDbDataAdapter(show_table);
DataTable table = new DataTable();
displayCourseID.Fill(table);
dataGridView_StudentInfo.DataSource = table;
I expected it to fill the dataGridView with the data from the database (Access) as table.
Note: I put the Student.CourseID as MultiValued in Access, will that affect the type?