Using Data Access Object (DAO) library in C#

JohnCTX 621 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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,009 questions
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,327 questions
No comments
{count} votes

Accepted answer
  1. Castorix31 65,791 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);
    }
    

0 additional answers

Sort by: Most helpful