Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VS 2005 SQL CE

Posted on 2007-03-24
10
Medium Priority
?
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 1000 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 1000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

730 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