SqlCeDataAdapter broken?

T

Tim Johnson

This code fails to compile saying SqlCeDataAdapte "does not contain a
definition for Fill":

using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlServerCe;
using System.Windows.Forms;
SqlCeDataAdapter da = new SqlCeDataAdapter(sql, conn);

ds = new DataSet();

da.Fill(ds);


When I type "da." Intellisense only shows these items available:

RowUpdating
RowUpdated
DeleteCommand
InsertCommand
UpdateCommand
SelectCommand

What happened to Fill??? I thought it was available on both CE and SQL
desktop, according to all the books!


--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
P

Peter Foot [MVP]

Make sure you have a reference to System.Data.Common in your project - this
contains the DataAdapter base class which the SqlCeDataAdapter inherits
these methods from.

Peter
 
T

Tim Johnson

Yep, that was it - I never know when to just have the "using" and when you
also need to manually add the Reference. You'd think without the reference
you'd get nothing working for dataadapter, but instead you get it
"partially" working. Very frustrating.

Thanks!

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
P

Peter Foot [MVP]

It's peculiar behaviour because on the desktop there is no
System.Data.Common.dll - all that functionality is included within the
System.Data assembly.

The key difference between "using" and adding a reference is that "using"
(or Imports for VB.NET) merely provides you with a shortcut to a namespace
within an assembly you have already referenced - it wont actually reference
the assembly in question.

For example if I want to use a SqlCeConnection I can't simply add:-
using System.Data.SqlServerCe;
because I have no reference to an assembly containing this namespace

On the other hand if I just add a reference to System.Data.SqlServerCe I
will need to use:-
System.Data.SqlServerCe.SqlCeConnection c = new
System.Data.SqlServerCe.SqlCeConnection();

In this case you'll want to do both both. And if you reference an assembly
which contains multiple namespaces, a good example is OpenNETCF.dll, then
you can use multiple using statements to directly refer to classes within
those namespaces e.g. after adding a reference to OpenNETCF.dll I could
add:-
using OpenNETCF.Diagnostics;
using OpenNETCF.Runtime.InteropServices;

This then allows me to create a process using
Process p = Process.Start("Someapp.exe");
or allocate some memory using
IntPtr pBuffer = MarshalEx.AllocHGlobal(16);

But without a "using" statement for other namespaces I would still have to
refer to them explictely e.g.
long freespace =
OpenNETCF.IO.StorageCard.GetDiskFreeSpace().FreeBytesAvailable;

I hope this clarifies things slightly and doesn't make it more confusing :)

Peter
 
T

Tim Johnson

Nope, I get all that. What I don't get is, before I added the correct
..Common reference, it didn't fail with "unknown namespace", which would have
been much more helpful. Instead it got *some* of the methods/properties of
the dataadapter - where in the heck did it pull those from if I didn't have
the .Common reference yet? And why wouldn't the 'using' statement fail and
say "cannot find a reference to satisfy this using statement". You know,
something actually useful.

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
P

Peter Foot [MVP]

I agree with you that it's rather unhelpful. Thankfully it is being changed
for .NETCF v2.0 where the content will be merged into the System.Data.dll
assembly - which is as it is in the full framework.
The reason that some of the methods show up is that SqlCeDataAdapter
inherits from DbDataAdapter in System.Data.Common but also implements the
IDataAdapter and IDbDataAdapter interfaces which are in System.Data.
Therefore the compiler knows that the class implements those specific
methods.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top