Solved

VS 2005 SQL CE

Posted on 2007-03-24
10
472 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:
xDJR1875 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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:xDJR1875
xDJR1875 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now