• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

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
0
Hardi
Asked:
Hardi
  • 5
  • 3
  • 2
4 Solutions
 
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now