Do you want to prepopulate / preload windows phone 7 database with bunch of data ?

Here’s how

Tools needed :

  • wp7 sdk 7.1
  • visual c# 2010 express
  • visual studio for windows phone
  • sql ce 3.5

01. Create Sql Ce 3.5 database using visual c# 2010 express, say database.sdf

02. Create tables, indexes, relationship and insert all data needed

03. Copy database.sdf and add it into your wp7 project as content; run wp7 project

database.sdf now on appdata

04. Copy database.sdf from appdata into isostore

see http://blog.arsanth.com/index.php/2011/06/02/working-with-pre-populated-sql-ce-databases-in-wp7/

05. do some select that targeting database.sdf in isostore
Note: in case you wonder why i include this step
http://blogs.msdn.com/b/sqlservercompact/archive/2009/04/01/after-moving-the-database-from-one-platform-to-other-the-first-sqlceconnection-open-takes-more-time.aspx

06. emulator still on, go pull database.sdf from isostore into harddisk

see http://msdn.microsoft.com/en-us/library/hh286408(v=vs.92).aspx
see copy part

07. Copy extracted database.sdf back into your wp7 project as content

08. and thats it, you can select data with  read only connection string to database.sdf on appdata

thanks to @ErikEJ

http://erikej.blogspot.com/2011/06/populating-windows-phone-mango-sql.html

About these ads