I am coding for pocket pc 2002. Strange error that took me a while to
recover from, but I don't understand why it works.

I have a Microsoft Access 2000 database exported into xml (data and
schema) via the dataset.writexml method. The xml is transfered to the
pocketpc and read in via readxml (schema first, and then data).

At some point I'm trying to find a particular value via setting up a
dataview on one of the tables, and setting the sort to the column I
want to index. I then use a textbox to enter my value I want to
search for, and then execute.

My code bombs with an invalidcastexception.

This is what the code was:
Dim i_location As Integer = 0
i_location = dv.Find(TextBox1.Text)

This works in vb.net 2003 perfectly fine. But on the compactframework
(v1.1), it throws the castexception.

At first I realized that my column is an integer, so I figure the
implicit conversion from string to integer is failing. (which does
not fail on the same code in a vb 2003 project). so I used
cint(textbox1.text) as my parameter for the find method. This failed
as well.

Through some manual debugging of my own, i realized that my xml schema
shows the column I'm searching is of datatype int16. An integer is
int32 in .NET, which is what i_location is. dv.find is supposed to
return an integer (int32) of the record I am looking for. The MSDN
documentation does not specify what valid parameters are for the
dv.find method. All examples use strings. This led me to believe it
would implicitly convert the string to whatever to search the dv. I
guess I was wrong? (but only in compactframework?)

To reiterate my findings, the bombing is coming from the actual FIND
method itself. Why?!?! I have to use cshort(textbox1.text) as my
parameter in order for the CompactFramework to work correctly. (again
vb.net has no problems with just cint(textbox1.text) or even just
textbox1.text for that matter.

Why is this?? Having to rely on changing this to cshort limits the
values I'm using for my text box because if the number is large enough
the cshort conversion fails hard. (obviously I should be coding
around this as good development would call for. I know I shouldn't be
relying on implicit conversions, but I want to know why it's even
happening!). What is different about the compactframework and the
regular framework in that the dataview find method will not process
the find unless the parameter matches the column value in type
explicitly? Is the dv.find method is supposed to take an OBJECT, so
it shouldn't matter what I pass it, correct? Apparently the CF
doesn't like this notion.

Second question is why does MS access see an integer as 2 bytes, but
.NET sees it as 4 bytes?? Shouldn't the machine itself define how big
an integer is? Or how big the word sizes are, etc?

RE: dotnet 2003/compact framework dataview find method invalidcastexception.. need explanation. by ilyatum

ilyatum
Tue Aug 10 19:51:17 CDT 2004

The first one is easy to explain: it's a bug in a Compact Framework which
would cause InvalidCastException in Find() in case argument type(s) and
sort key type(s) are mismatched.
You've found the workaround already - cast the find argument to the key
type. That's in fact a good idea from performance point of view as well.
This bug has been fixed in SP2, as far as I remember. You can install SP2
to fix that problem.

As to your second question, "Integer" could mean pretty much anything, it
depends on specific language running on specific platform.

In VB.Net "Integer" is 32 bit signed value, alias of System.Int32.
That might not be the case with other languages/databases even running on
the same computer.
Here's some quote from MSDN:

"Caution If you are interfacing with components written in Visual Basic
version 6.0, for example Automation or COM objects, keep in mind that
Integer has a different data width (16 bits) in Visual Basic 6.0. If you
are passing a 16-bit argument to such a component, declare it as Short
instead of Integer in Visual Basic .NET."

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
> From: mmcd79@tampabay.rr.com (MCDONAMW)
> Newsgroups: microsoft.public.dotnet.framework.compactframework
> Subject: dotnet 2003/compact framework dataview find method
invalidcastexception.. need explanation.
> Date: 10 Aug 2004 15:40:24 -0700
> Organization: http://groups.google.com
> Lines: 57
> Message-ID: <dc3383db.0408101440.2ec132d@posting.google.com>
> NNTP-Posting-Host: 207.218.78.144
> Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: 8bit
> X-Trace: posting.google.com 1092177625 17491 127.0.0.1 (10 Aug 2004
22:40:25 GMT)
> X-Complaints-To: groups-abuse@google.com
> NNTP-Posting-Date: Tue, 10 Aug 2004 22:40:25 +0000 (UTC)
> Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!news-out!newsfee
d.cwix.com!news1.optus.net.au!optus!news-spur1.maxwell.syr.edu!news.maxwell.
syr.edu!postnews2.google.com!not-for-mail
> Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:59117
> X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
>
> I am coding for pocket pc 2002. Strange error that took me a while to
> recover from, but I don't understand why it works.
>
> I have a Microsoft Access 2000 database exported into xml (data and
> schema) via the dataset.writexml method. The xml is transfered to the
> pocketpc and read in via readxml (schema first, and then data).
>
> At some point I'm trying to find a particular value via setting up a
> dataview on one of the tables, and setting the sort to the column I
> want to index. I then use a textbox to enter my value I want to
> search for, and then execute.
>
> My code bombs with an invalidcastexception.
>
> This is what the code was:
> Dim i_location As Integer = 0
> i_location = dv.Find(TextBox1.Text)
>
> This works in vb.net 2003 perfectly fine. But on the compactframework
> (v1.1), it throws the castexception.
>
> At first I realized that my column is an integer, so I figure the
> implicit conversion from string to integer is failing. (which does
> not fail on the same code in a vb 2003 project). so I used
> cint(textbox1.text) as my parameter for the find method. This failed
> as well.
>
> Through some manual debugging of my own, i realized that my xml schema
> shows the column I'm searching is of datatype int16. An integer is
> int32 in .NET, which is what i_location is. dv.find is supposed to
> return an integer (int32) of the record I am looking for. The MSDN
> documentation does not specify what valid parameters are for the
> dv.find method. All examples use strings. This led me to believe it
> would implicitly convert the string to whatever to search the dv. I
> guess I was wrong? (but only in compactframework?)
>
> To reiterate my findings, the bombing is coming from the actual FIND
> method itself. Why?!?! I have to use cshort(textbox1.text) as my
> parameter in order for the CompactFramework to work correctly. (again
> vb.net has no problems with just cint(textbox1.text) or even just
> textbox1.text for that matter.
>
> Why is this?? Having to rely on changing this to cshort limits the
> values I'm using for my text box because if the number is large enough
> the cshort conversion fails hard. (obviously I should be coding
> around this as good development would call for. I know I shouldn't be
> relying on implicit conversions, but I want to know why it's even
> happening!). What is different about the compactframework and the
> regular framework in that the dataview find method will not process
> the find unless the parameter matches the column value in type
> explicitly? Is the dv.find method is supposed to take an OBJECT, so
> it shouldn't matter what I pass it, correct? Apparently the CF
> doesn't like this notion.
>
> Second question is why does MS access see an integer as 2 bytes, but
> .NET sees it as 4 bytes?? Shouldn't the machine itself define how big
> an integer is? Or how big the word sizes are, etc?
>