2015-04-05 185 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); 
相关问题