[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


Hi,

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

8--->
        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");
<---8

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!

Thanks

Paul
-------------- 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