I seem to have hit a problem when try to drag data from an Access file. I know I can do it as I've populated some combo boxes using pretty much the same code, however, the code below is returning nothing and I cannot see why!
Any help would be appreciated
Expand|Select|Wrap|Line Numbers
- private void searchInformation(List<string> detail, List<bool> opts)
- {
- int id = 0;
- string commandString = "Select TutorID from TutorNames WHERE Name = '" + detail[0] + "'";
- OleDbCommand objCommand = new OleDbCommand(commandString, conn);
- conn.Open();
- OleDbDataReader reader = objCommand.ExecuteReader();
- while (reader.Read() == true)
- {
- try
- {
- id = (int)reader["TutorID"];
- }
- catch (Exception e)
- { }
- }
- conn.Close();
- if (id == 0)
- {
- MessageBox.Show(detail[0] + " doesn't exist on the database", "Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- MessageBox.Show(detail[0] + " exists, ID = " + id.ToString(), "Database");
The only thing I can think of is that there are some escape characters at the end of the text (either being passed in or in the database) - everything else seems valid.
I have tried
"Select * from TutorNames where Name = '" + details[0] + "'" to see if I can see TutorID, but nothing is being returned.
Additionally, I've tried another tack using a DataSet and DataTable in a similar way to the ways shown on MSDN, but still nothing.
Any clues would be appreciated!
Thanks
Paul