C# 和 DAO。为什么 RS.Fields(“ColName”) 不起作用?
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");
我想最后一条指令适用于 VBA 或 VB.NET,为什么它不适用于 C# ?
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# ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用方括号,显式声明属性名称(在本例中为 Value)并将其转换为字符串:
Use square brackets, explicitly state the property name which in this case is Value and cast it to a string:
尝试 String Val = RS.Fields["ColName"]; C# 使用方括号来引用集合
try String Val = RS.Fields["ColName"]; C# uses square brackets to reference collections