[Mono-list] Problem accessing an Access database in C#

Paul Johnson paul at all-the-johnsons.co.uk
Sat Oct 15 12:47:28 EDT 2011


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

Any help would be appreciated

        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);
            OleDbDataReader reader = objCommand.ExecuteReader();
            while (reader.Read() == true)
                    id = (int)reader["TutorID"];
                catch (Exception e)
                { }

            if (id == 0)
                MessageBox.Show(detail[0] + " doesn't exist on the
database", "Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
            MessageBox.Show(detail[0] + " exists, ID = " + id.ToString(),

details[0] contains the name to be searched for (directly from a TextBox).
TutorID exists in the TutorNames table and for test purposes, I'm using data
that I know exists.

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!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20111015/a3ae34b2/attachment-0001.html 

More information about the Mono-list mailing list