VS 2005 SQL CE

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
LVL 6
HardiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RickJCommented:
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
HardiAuthor Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

HardiAuthor Commented:
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
RickJCommented:
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
HardiAuthor Commented:
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
RickJCommented:
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
HardiAuthor Commented:
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
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Once you actually get it on a real machine instead of an emulator, you will see the updated database.
0
HardiAuthor Commented:
Really?
Ok thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.