views:

297

answers:

2

Hello,

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.

A: 

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

I am certain that I have the date column, and further more the table has rows in it. Regenerating does not solve anything...Using typed DataSets the task is solved.The issue encountered was at SqlCeResultSet, and the issue was not accessing data, but accessing column names.If I execute rs.GetDateTime(1), where 1 is the column ordinal, the method returns data.If I execute rs.GetOrdinal("MyDateColumn") the method throws the previusly mentioned exception; and more peculiar, if I execute rs.GetName(1) the method returns the string "MyDateColumn"...Do you have any ideeas?
Vlad
+1  A: 

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"));
MusiGenesis

related questions