question

JohnCTX-6479 avatar image
0 Votes"
JohnCTX-6479 asked Castorix31 commented

Using Data Access Object (DAO) library in C#

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

dotnet-csharpoffice-vba-devwindows-forms
screenshot-36.png (136.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered Castorix31 commented

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);
 }
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In addition, users who choose to use the Data Access Object library assembly reference need to download and install the Microsoft Access 2010 Runtime utility.

Otherwise, they will keep getting a myriad of runtime and compile error messages stating that these libraries are not registered within the Visual Studio IDE.

Does that make sense?

Regards,

JohnCTX

0 Votes 0 ·

I looked my executable using DAO and it is just linked with DAO360.dll (C:\Program Files (x86)\Common Files\Microsoft Shared\DAO\dao360.dll)
For testing, I unregistered/registered the DLL (with regsvr32) and then I needed to add again Interop.DAO.dll to be able to re-compile my program

0 Votes 0 ·