나는 Windows phone 용 간단한 응용 프로그램을 만들고 있습니다. 데이터베이스를 만들고 싶고 데이터베이스에 여러 항목 (10 개까지 허용)을 갖고 싶습니다. 나는 초보자이고 내가 본 모든 튜토리얼은 sth가 "add"또는 sth와 같은 버튼에 데이터베이스에 항목을 추가하는 것에 관한 것입니다. 필자는 데이터베이스에있는 여러 항목을 갖고 싶어하므로 사용자가 사용할 수 있도록 준비해야합니다. 이것을 어떻게 할 수 있습니까? 내가 아직 초보자이기 때문에 분명한 방법으로 저에게 편지를 보내주십시오. 예제 또는 튜토리얼 링크를 제공 할 수 있다면 좋을 것입니다. 고마워!windows phone 항목으로 데이터베이스 생성
1
A
답변
2
사전로드 된 DB가 필요한 경우 응용 프로그램에 sqlCe DB를 추가하고 시드 데이터로 db를 채울 수 있습니다. 그러면 DBContext 생성자가 호출되는 동안 DB 파일을 ISO 저장소에 복사 할 수 있습니다.
public Moviadb1DataContext (string connectionString) : base(connectionString)
{
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
if (!iso.FileExists("Moviadb1.sdf"))
{
MoveReferenceDatabase();
}
if (!DatabaseExists())
CreateDatabase();
}
public static void MoveReferenceDatabase()
{
// Obtain the virtual store for the application.
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
// Create a stream for the file in the installation folder.
using (Stream input = Application.GetResourceStream(new Uri("Moviadb1.sdf", UriKind.Relative)).Stream)
{
// Create a stream for the new file in isolated storage.
using (IsolatedStorageFileStream output = iso.CreateFile("Moviadb1.sdf"))
{
// Initialize the buffer.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the file from the installation folder to isolated storage.
while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
output.Write(readBuffer, 0, bytesRead);
}
}
}
}
데이터의 양이 매우 적은 경우 참조 DB를 이동하는 대신 시드 데이터를 추가 할 수도 있습니다.
public ListenDataDataContext (string connectionString) : base(connectionString)
{
if (!DatabaseExists())
{
CreateDatabase();
List<Audiables> PreLoads = new List<Audiables>();
PreLoads.Add(new Audiables { Category = 1, Name = "I want To Eat", AudioLocation = "Sounds/Food/1_IwantToEat.wma", ImageLocation = "Images/Food/1_IwantToEat.jpg" });
PreLoads.Add(new Audiables { Category = 1, Name = "I want To Drink", AudioLocation = "Sounds/Food/1_IwantToDrink.wma", ImageLocation = "Images/Food/1_IwantToDrink.jpg" });
PreLoads.Add(new Audiables { Category = 2, Name = "I want A Ticket", AudioLocation = "Sounds/Travel/1_IwantATicket.wma", ImageLocation = "Images/Travel/1_IwantATicket.jpg" });
PreLoads.Add(new Audiables { Category = 2, Name = "I want To Sit", AudioLocation = "Sounds/Travel/1_IwantToSit.wma", ImageLocation = "Images/Travel/1_IwantToSit.jpg" });
PreLoads.Add(new Audiables { Category = 3, Name = "How Much Is That", AudioLocation = "Sounds/Shopping/1_HowMuchIsThat.wma", ImageLocation = "Images/Shopping/1_HowMuchIsThat.jpg" });
PreLoads.Add(new Audiables { Category = 3, Name = "Please Take the Money", AudioLocation = "Sounds/Shopping/1_PleaseTakeTheMoney.wma", ImageLocation = "Images/Shopping/1_PleaseTakeTheMoney.jpg" });
Audiables.InsertAllOnSubmit(PreLoads);
this.SubmitChanges();
}
}
만드는 해피 응용 프로그램 :
1
가장 좋은 방법은 Windows Phone Code Samples의 "로컬 데이터베이스 샘플"을 확인하는 것입니다!
관련 문제
- 1. Windows Phone 7 데이터베이스
- 2. Windows Phone 7 액세스 데이터베이스
- 3. 로컬 데이터베이스 Windows Phone 7
- 4. Windows Phone 7의 데이터베이스 테스트 mango
- 5. windows phone 7 및 sqlite 데이터베이스
- 6. Windows Phone 7.5 - 로컬 SQL 데이터베이스
- 7. 로컬 데이터베이스 VS 2010 Windows Phone
- 8. Windows Phone 7 응용 프로그램의 데이터베이스 사용
- 9. Windows Phone Mango vs Windows Phone 7
- 10. Windows phone
- 11. Windows Phone 7의 App.config?
- 12. XNA GameTime Windows Phone
- 13. Windows Phone 7 쿠키 지우기
- 14. DateTime.Now in Windows phone 7
- 15. windows phone 푸시 알림 타일에
- 16. Windows phone 데이터 바인딩 문제
- 17. Windows Phone 7.1 SDK와 Windows Phone 7.5 SDK
- 18. Windows phone 7 app on windows phone 8
- 19. Windows Phone 7.1에서 Windows phone store 테스트 키트를 사용하는 방법
- 20. Windows Phone에서 데이터베이스 작업
- 21. MediaElement Windows Phone 7
- 22. Windows Phone 7에서 UIElement.InvalidateVisual
- 23. windows phone autocompletebox
- 24. Windows Phone 7 - 비활성화?
- 25. ProgressBar Windows phone 7?
- 26. Windows Phone (MediaElement 포함)
- 27. Windows phone 7
- 28. Windows Phone 7 - WebBrowserTask
- 29. Windows Phone 사용자 인증
- 30. 센서가있는 windows phone mvvm
내가 사용 App.xaml.cs를 이 뭔가를 얻었다 (FoodDataContext의 dB = 새로운 FoodDataContext (FoodDataContext.DBConnectionString)) { \t \t \t \t 경우 (db.DatabaseExists() == false) { // 데이터베이스 만들기 db.CreateDatabase(); \t \t \t \t } } 과 Main.xaml.cs에 내가 내 DB를로드 물건을 가지고 있지만 매번 내가 최대 onNagiatedTo 방법은 데이터베이스의 항목을 만드는 시동 거기 onNavigatedTo 방법이이 항목을 중복 이것을 막을 수있는 방법이 있습니까? – Sandra
미리로드 할 데이터가 적은 경우 app.xaml.cs에서 두 번째 방법을 사용하고 다른 곳에서는 첫 번째 방법을 동일한 위치에서 시도하십시오 –