M
MCDONAMW
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?
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?