Solved

VS 2005 SQL CE

Posted on 2007-03-24
10
477 Views
Last Modified: 2010-04-16
I am creating a smart device application using VS 2005.
I need it to connect to a SQL CE (later), but I don't have the device connected now.
What is the best way of doing this? I am experienced with SQL but new to VS .NET and SQL CE

I need to know the following:
- How to make the connection. Do I add BindingSource to the form? Do I need to add any "using"s?
- Using a datagrid to display the data
- Execute SQL queries to execute a command (eg. insert) or to get a record from the database (eg. select)

Thanks in advance
0
Comment
Question by:Hardi
  • 5
  • 3
  • 2
10 Comments
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 250 total points
ID: 18785483
It is pretty much the same thing as if you were using .NET to connect to regular SQL Server.

You will need to download a couple things to help you along though.

1) Download the .Net Framework Compact Edition to your development machine. (This is what your smart device will use instead of the regular .Net Framework) This is smaller yet contains much of the same stuff, only built for smart devices.
2) Download SQL CE to your SQL Server machine.
NOTE: There should be several developer kits you will want to download that have instructions and samples as well. Here are a couple links to those.

http://www.microsoft.com/sql/prodinfo/previousversions/sqlce/ce20.mspx
http://www.microsoft.com/downloads/details.aspx?familyid=0C1B0A88-59E2-4EBA-A70E-4CD851C5FCC4&displaylang=en

The following link will take you to alisting of downloads and sdks for smart device development
http://www.microsoft.com/downloads/browse.aspx?displaylang=en&productID=3B68F15E-2D20-437A-8C20-E1E764F9CFAD

0
 
LVL 8

Assisted Solution

by:RickJ
RickJ earned 250 total points
ID: 18786579
Hello Hardi,
I am in a similar situation to you, but just a bit farther down the track.. After you have downloaded the above, I would have a look at the following series of video tutorials, they step you through everything you need to know about starting SQL Server CE development, from basic data app, through to RDA.
http://channel9.msdn.com/ShowPost.aspx?PostID=209464
I would also investigate SqlCeResultSet, a small but informative link about this is here.
http://www.ureader.com/message/999329.aspx
As far as "using's" this is it "System.Data.SqlServerCe"

Hope this helps.
0
 
LVL 6

Author Comment

by:Hardi
ID: 18787853
Thanks for getting me started, I've downloaded and installed them.
Could we please go back to my questions...

What I have done:
- Added new connection from Server Explorer: Microsoft SQL Server Mobile Edition (.NET Framework Data Provider for SQL Server CE)
- Created a table: testdb with 5 columns
- Put in 1 record to the table manually
- Added BindingSource (bindingSource1), selected Database, then testdb (the one I just created)
- testdbDataset was automatically added
- Set dataGrid1's DataSource property to bindingSource1

When I run the program (also in design time) I could only see the column header in dataGrid1, with no data. How do I display the data?

Then what is the code toI add a record?
I followed the example you gave me RickJ, thanks for that... but I got an error here

conn = new SqlCeConnection("Data Source = \"E:\\My Documents\\Visual Studio 2005\\Projects\\DeviceApplication2\\DB\\testdb.sdf\";");

it says the path is not valid. I copy-pasted the connection string from the database (from server explorer), changing " to \" and \ to \\
Did I miss something?

Thank you.
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 6

Author Comment

by:Hardi
ID: 18788239
I've made everything work.
But there is a strange thing. Everytime I quit and rerun the application (on emulator, or double-click the exe file directly), the database is always empty. (I have added records at runtime). Any idea why?
I don't really know what I am doing here... I just got it work by trial error =P
0
 
LVL 8

Expert Comment

by:RickJ
ID: 18790028
When you run from within Visula Studio it creates a copy of the database to work with.
If you click on the "Show All Files" button in your solution explorer you will see the "bin" directory.
The database file should be located in the "bin\debug" directory.
You could also use Query Analyser on your device to look at the database on your device.
0
 
LVL 6

Author Comment

by:Hardi
ID: 18790933
I don't have the database in the debug directory... did I do something wrong?
Can i use query analyser on the pocket pc emulator?
0
 
LVL 8

Assisted Solution

by:RickJ
RickJ earned 250 total points
ID: 18791753
1.I don't have the database in the debug directory... did I do something wrong?
Maybe, have a read of this, it is really important to understand when doing mobile apps. It explains it much better than I can :)
http://msdn2.microsoft.com/en-us/library/ms233817(VS.80).aspx

2.Can i use query analyser on the pocket pc emulator?
Yes you can. Just open Query Analyser and connect to the db. It will usuallybe in the application's directory.
0
 
LVL 6

Author Comment

by:Hardi
ID: 18791890
I have added the database to the project, so it created a new dataset (i deleted the old dataset)
Now I can see the .sdf file in the debug directory.
But still, that file is never updated.
This is really confusing.
I opened up query analyser, but i dont see any database
0
 
LVL 17

Assisted Solution

by:Daniel Reynolds
Daniel Reynolds earned 250 total points
ID: 18793378
Once you actually get it on a real machine instead of an emulator, you will see the updated database.
0
 
LVL 6

Author Comment

by:Hardi
ID: 18798179
Really?
Ok thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question