SqlCeResultSet 问题
我有一个 SmartDevice 项目(.NetCF 2.0),配置为在美国 Windows Mobile 5.0 Pocket PC R2 模拟器上进行测试。我的项目使用SqlCe 3.0。了解 SmartDevice 项目对设备内存“更加小心”后,我正在使用 SqlCeResultSets。结果集是强类型的,由 Visual Studio 2008 使用自定义工具 MSResultSetGenerator 自动生成。
我面临的问题是结果集无法识别任何列名。字段的自动生成代码不起作用。在我使用的客户端代码中,
InfoResultSet rs = new InfoResultSet();
rs.Open();
rs.ReadFirst();
string myFormattedDate = rs.MyDateColumn.ToString("dd/MM/yyyy");
当模拟器上的执行到达 rs.MyDateColumn 时,应用程序会抛出 System.IndexOutOfRangeException。
调查堆栈跟踪
at System.Data.SqlServerCe.FieldNameLookup.GetOrdinal()
at System.Data.SqlServerCe.SqlCeDataReader.GetOrdinal()
我已经测试了 GetOrdinal 方法(在继承 SqlCeResultSet 的自动生成的类中):
this.GetOrdinal("MyDateColumn"); // throws an exception
this.GetName(1); // returns "MyDateColumn"
this.GetOrdinal(this.GetName(1)); //throws an exception :)
[编辑添加]
该表存在并且它充满了数据。 使用类型化数据集就像一个魅力。 重新生成 SqlCeResultSet 并不能解决问题,问题仍然存在。
问题基本上是我无法通过名称访问列。 数据可以通过
this.GetDateTime(1)
using the column ordinal. The application fails executingthis.GetOrdinal("MyDateColumn")
.另外,我已将 Visual Studio 2008 更新到 Service Pack 1。 另外,我正在使用 Windows XP SP 2 的虚拟机上开发该项目,但我认为介质是否虚拟对开发没有影响。
我做错了什么或者我错过了什么吗?
谢谢。
I have a SmartDevice project (.NetCF 2.0) configured to be tested on the USA Windows Mobile 5.0 Pocket PC R2 Emulator. My project uses SqlCe 3.0. Understanding that a SmartDevice project is "more carefull" with the device's memory I am using SqlCeResultSets. The result sets are strongly typed, autogenerated by Visual Studio 2008 using the custom tool MSResultSetGenerator.
The problem I am facing is that the result set does not recognize any column names. The autogenerated code for the fields does not work. In the client code I am using
InfoResultSet rs = new InfoResultSet();
rs.Open();
rs.ReadFirst();
string myFormattedDate = rs.MyDateColumn.ToString("dd/MM/yyyy");
When the execution on the emulator reaches the rs.MyDateColumn the application throws an System.IndexOutOfRangeException.
Investigating the stack trace
at System.Data.SqlServerCe.FieldNameLookup.GetOrdinal()
at System.Data.SqlServerCe.SqlCeDataReader.GetOrdinal()
I've tested the GetOrdinal method (in my autogenerated class that inherits SqlCeResultSet):
this.GetOrdinal("MyDateColumn"); // throws an exception
this.GetName(1); // returns "MyDateColumn"
this.GetOrdinal(this.GetName(1)); //throws an exception :)
[edit added]
The table exists and it's filled with data.
Using typed DataSets works like a charm.
Regenerating the SqlCeResultSet does not solve the issue, the problem remains.
The problem basically is that I am not able to access a column by it's name.
The data can be accessed trough
this.GetDateTime(1)
using the column ordinal.
The application fails executing
this.GetOrdinal("MyDateColumn")
.
Also I have updated Visual Studio 2008 to Service Pack 1.
Additionaly I am developing the project on a virtual machine with Windows XP SP 2, but in my opinion if the medium is virtual or not should have no effect on the developing.
Am I doing something wrong or am I missing something?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
this.GetOrdinal("MyDateColumn")
返回名称为“MyDateColumn”的列号。要使用列名称获取
DateTime
值,您需要执行以下操作:this.GetOrdinal("MyDateColumn")
returns the number of the column that has the name "MyDateColumn".To get a
DateTime
value using the column name, you need to do this:您确定数据库中确实有日期列吗?
如果没有,您可以尝试再次生成结果集。
Are you sure that you actually have the date column in your database?
If not, you could try to generate the resultset again.