Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server CE / February 2008

Tip: Looking for answers? Try searching our database.

SQLce 3.5 databound to C# 2008 control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen Reilly - 21 Feb 2008 13:33 GMT
Hi,
   I created a ce database and upgraded it using VS2008. I added a
datasource to a C# windows application and created all of the default
DataSets and TableAdapters. I've populated some of the tables and I'm trying
various different methods of usefully extracting that data.

   I'm probably missing steps here but having dropped a combobox onto a
form I set its databinding properties to:

DataSource = TableAdapter
DisplayMember = Name Field
DisplayValue = ID Field

When I preview the data the recordset is returned correctly. On form load
however the combobox remains empty. I figure I probably have to call GetData
or Fill somewhere on the TableAdapter but I can't figure out where.

I then initialised an instance of the TableAdapter and DataTable in code.
Doing so means that I can assign the records returned from the GetData method
of the TableAdapter to the instance of the DataTable. Then I can iterate
through the DataRow objects in the DataTable and manually add them
individually to the combobox. This method works so the underlying structure
should be fine.

Is there any way of doing this visually through the ide or how many things
am I doing wrong above. How should controls be bound to underlying dataset?

Also should I have the entire database as a single dataset with
TableAdapters for each table or should I use seperate datasets or does it
depend on other factors too complex for a concise answer? I have done some
research into the benefits of one system compared to another but I can't
really get a handle on it. Should I be trying to use Linq for this?

Any help or pointers greatfully accepted. I'm creating all of this from
scratch so if need be I can use an entirely different approach.

Stephen
Ginny Caughey [MVP] - 21 Feb 2008 15:49 GMT
Stephen,

Most of the demos I've seen do use a single DataSet rather than a separate
one for each table, although you could do it either way. I imagine there is
some overhead to having multiple DataSets. You do need need to call the
TableAdapter.Fill method for each table, and the form Load event handler is
usually where people do that. The code generated by the Data Source tool in
VS 2008 already wired up the connection between specific table adapters and
GUI controls for you, but if you didn't use those tools, you'd need to
establish the data binding programmaticly.

If you're interested in experimenting, you might enjoy trying Sync Services
for ADO.NET if this is a desktop app. (If it's a device app, that isn't an
option yet.) The tools for creating a SQL Compact data cache from data in
SQL Server and syncing the data back are quite good. The 3rd featured video
on this page http://msdn2.microsoft.com/en-us/sync/default.aspx called
"Introduction to Sync Services for ADO.NET and the Visual Studio Sync
Designer" illustrates the process.

Signature

Ginny Caughey
Device Application Development MVP

www.wasteworks.com
Scalehouse and Billing Software for Waste Management

> Hi,
>    I created a ce database and upgraded it using VS2008. I added a
[quoted text clipped - 38 lines]
>
> Stephen
Stephen Reilly - 21 Feb 2008 16:40 GMT
Ginny,

        thanks for the quick reply.

> Most of the demos I've seen do use a single DataSet rather than a separate
> one for each table, although you could do it either way. I imagine there is
Grand so. I was worried that referencing the full dataset on each form even
though I may only need to retrieve a single field might have been overkill.
I'll have to read up more on how they access and store the data while in use.

> some overhead to having multiple DataSets. You do need need to call the
> TableAdapter.Fill method for each table, and the form Load event handler is
> usually where people do that. The code generated by the Data Source tool in
> VS 2008 already wired up the connection between specific table adapters and
> GUI controls for you, but if you didn't use those tools, you'd need to
> establish the data binding programmaticly.
I went back and dragged a field (set as a combobox) from the DataSource list
onto a form. When I previewed the data again the table was correctly returned
but when I ran the form the control was empty. I tried this with and without
the databound options set on the control. It would save heaps of time if I
could get a few forms working this way.

> If you're interested in experimenting, you might enjoy trying Sync Services
> for ADO.NET if this is a desktop app. (If it's a device app, that isn't an
That looks really interesting, thanks for the link. It would have saved bags
of code a few years ago :)

Stephen
Ginny Caughey [MVP] - 21 Feb 2008 18:01 GMT
Stephen,

I wouldn't worry about referencing a single dataset from several places. The
memory used by the dataset won't be released until there are no longer any
active references to it anywhere, but the reference itself is just a
pointer.

I think if you watch that video you'll get a good idea how the databound
controls work with SQL Compact and VS 2008, even if you don't need to use
Sync Services at the moment. If you have more questions after viewing it,
just ask.

Signature

Ginny Caughey
Device Application Development MVP

www.wasteworks.com
Scalehouse and Billing Software for Waste Management

> Ginny,
>
[quoted text clipped - 38 lines]
>
> Stephen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.