Created
May 25, 2015 02:30
-
-
Save ChrisBriggsy/f08aae8a7aa48b1b2dc5 to your computer and use it in GitHub Desktop.
Step 7. Using SQLite in Windows 10 IoT Core Insider Preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SQLite.Net.Attributes; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Runtime.InteropServices.WindowsRuntime; | |
using Windows.Foundation; | |
using Windows.Foundation.Collections; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Controls.Primitives; | |
using Windows.UI.Xaml.Data; | |
using Windows.UI.Xaml.Input; | |
using Windows.UI.Xaml.Media; | |
using Windows.UI.Xaml.Navigation; | |
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 | |
namespace SQLitePiExample | |
{ | |
/// <summary> | |
/// An empty page that can be used on its own or navigated to within a Frame. | |
/// </summary> | |
public sealed partial class MainPage : Page | |
{ | |
string path; | |
SQLite.Net.SQLiteConnection conn; | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite"); | |
conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path); | |
conn.CreateTable<Message>(); | |
} | |
private void Retrieve_Click(object sender, RoutedEventArgs e) | |
{ | |
var query = conn.Table<Message>(); | |
string text = ""; | |
foreach (var message in query) | |
{ | |
text = text + " " + message.Content; | |
} | |
textBlock.Text = text; | |
} | |
private void Add_Click(object sender, RoutedEventArgs e) | |
{ | |
var s = conn.Insert(new Message() | |
{ | |
Content = textBox.Text | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment