开发者

SqlCeResultSet Problem

开发者 https://www.devze.com 2022-12-13 13:18 出处:网络
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 car

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.G开发者_如何学编程etName(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.


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:

this.GetDateTime(this.GetOrdinal("MyDateColumn"));


Are you sure that you actually have the date column in your database? If not, you could try to generate the resultset again.

0

精彩评论

暂无评论...
验证码 换一张
取 消