Using Data Access Object (DAO) library in C#

JohnCTX 636 Reputation points
2021-01-24T02:27:53.133+00:00

I have this slight technicality going on.
Here is my screenshot:

59921-screenshot-36.png

I have caught this error exception runtime error. Users who are familiar with DAO and ADODB Access libraries can provide me some assistance.

Regards,

JohnCTX

Developer technologies | Windows Forms
Developer technologies | Visual Basic for Applications
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,686 Reputation points
    2021-01-24T07:29:27.583+00:00

    You do a loop on columns with Fields[i]...

    For example, a test where I read the second column (index = 1, named "LastName") of an "Employees" table =>

    string sMyDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string sPath = sMyDocumentsPath + "\\Employees.mdb";
    string sPassword = "toto";
    DBEngine dbEngine = new DBEngine();
    try
    {
        Database db = dbEngine.OpenDatabase(sPath, true, false, ";PWD=" + sPassword);
        if (db != null)
        {
            Recordset rst = db.OpenRecordset("SELECT * FROM Employees WHERE Salary >= 40000");
            while (!rst.EOF)
            {
                // Second column
                comboBox1.Items.Add(rst.Fields[1].Value);
                //comboBox1.Items.Add(rst.Fields["LastName"].Value);
                rst.MoveNext();
            }
        }
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show("Database Error : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.