Re: Late Binding / CF
- From: "Christopher Fairbairn [MVP]" <christopher@xxxxxxxxxxxxxx>
- Date: Mon, 23 Mar 2009 10:15:50 +1300
Hi James.
"James Hetfield" <james@xxxxxxxxxxxx> wrote in message
news:%23Ev7EjiqJHA.724@xxxxxxxxxxxxxxxxxxxxxxx
But I get the error "Late Binding not supported"
Is there an easy way to get around this problem?
I assume there is some additional code after the snippet you provided, such
as something like the following:
Dim count as Int16 = dr.FieldCount
It will be this code which is causing the late binding error during
compilation.
VB.NET supports a feature called Late Binding. The 'dr' variable is typed as
Object, yet on the desktop you can call methods and properties on it, as if
it was typed as SqlCEDataAdapter or SqlDataAdapter.
It is only when the application runs (i.e. "later" than compilation where
this check is usually made) that the runtime determines if these methods
actually exist and "binds" to them or throws an exception.
At compile time the compiler only knows it has a variable of type Object, so
it can not determine if the method or function calls you make in this manor
are valid.
Although late binding works on the desktop, as discussed in the article
"Differences from Desktop in .NET Compact Framework Development" (available
at http://msdn.microsoft.com/en-us/library/t340010s.aspx) it is not a
supported feature when targeting a PDA.
As such replacing the line
Dim dr as Object
with
Dim dr as IDbDataAdapter
Should allow you to work with either data adapter. This doesn't require late
binding as both classes implement the IDbDataAdapter interface and hence can
be guarenteed at compile time to contain the methods and properties it
defines.
Hope this helps,
Christopher Fairbairn
.
- Follow-Ups:
- Re: Late Binding / CF
- From: James Hetfield
- Re: Late Binding / CF
- References:
- Late Binding / CF
- From: James Hetfield
- Late Binding / CF
- Prev by Date: Late Binding / CF
- Next by Date: Restart Windows Mobile Device Programatically
- Previous by thread: Late Binding / CF
- Next by thread: Re: Late Binding / CF
- Index(es):
Relevant Pages
|