tags:

views:

563

answers:

2
    dao.DBEngine DBE;
    dao.Database DB;
    dao.Recordset RS;
    string DBPath;

        DBPath = "C:\\Test\\test.mdb";
        DBE = new dao.DBEngine();
        DB = DBE.OpenDatabase(DBPath, false, false, "");
        RS = DB.OpenRecordset("SELECT * FROM TEST", dao.RecordsetTypeEnum.dbOpenSnapshot, 0, dao.LockTypeEnum.dbOptimistic);
        RS.MoveLast(0);
        RS.MoveFirst();
        String Val = RS.Fields("ColName");

Last instruction works in VBA or VB.NET I think, why doesn't it work on C# ?

+1  A: 

try String Val = RS.Fields["ColName"]; C# uses square brackets to reference collections

Dug
+1  A: 

Use square brackets, explicitly state the property name which in this case is Value and cast it to a string:


string Val = (string)RS.Fields["ColName"].Value;
Alfred Myers