2015-04-05 183 views
3

我正在創建一個SQLite數據庫Visual StudioXamarinC#如何在Visual Studio中用c#創建SQLite數據庫?

我應該注意,這僅適用於android

據我所知,在這個類中,我必須創建SQLite數據庫,並使其能夠添加,刪除和檢索數據。

我還應該注意到,有一個單獨的類來調用此類中的方法。

我對此很新,我不知道如何做到這一點。

我讀過教程,我看過一小時長的視頻,但我仍然無法弄清楚這一點。

任何幫助將不勝感激。

這是我使用的,並且必須遵循類模板:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 

using BB.Mobile.Models; 

namespace BB.Mobile 
{ 
    /// <summary> 
/// A class to provide a single interface for interacting with all SQLite data operations for stored tracking points. 
/// </summary> 
class DataManager 
{ 
    /// <summary> 
    /// Will compile and return all matching unsynchronized ping data from the SQLite database. 
    /// </summary> 
    /// <returns></returns> 
    public List<PingGroup> GetUnsynchronizedPings() 
    { 
     List<PingGroup> unsynchronizedPings = new List<PingGroup>(); 

     // TODO: Retrieve all unsynchronized pings from the SQLite database and return them to the caller. 

     return unsynchronizedPings; 
    } 

    /// <summary> 
    /// Insert a single ping group into the SQLite ping database. 
    /// </summary> 
    /// <param name="pingGroup"></param> 
    public void AddUnsynchronizedPing(PingGroup pingGroup) 
    { 
     // TODO: Add the passed ping group parameter into the SQLite database as new/unsynchronized. 


    } 

    /// <summary> 
    /// Mark all open and unsynchronized pings in the database as synchronized. 
    /// </summary> 
    public void SetAllPingsSynchronized() 
    { 
     // TODO: Delete all database data or set it as synchronized using a flag. 

    } 
} 
} 
+0

你讀過這個嗎? http://erikej.blogspot.dk/2014/10/database-first-with-sqlite-in-universal.html – ErikEJ 2015-04-05 11:46:18

回答

2

SQLite Component具有非常清晰的文檔 - 有一些具體的事情你不明白嗎?

using SQLite; 
// ... 

public class Note 
{ 
    [PrimaryKey, AutoIncrement] 
    public int Id { get; set; } 
    public string Message { get; set; } 
} 

// Create our connection 
string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal); 
var db = new SQLiteConnection (System.IO.Path.Combine (folder, "notes.db")); 
db.CreateTable<Note>(); 

// Insert note into the database 
var note = new Note { Message = "Test Note" }; 
db.Insert (note); 
相關問題