I have followed the article (link in the question), added the code and the button click handlers. The SQLite installation details are incorrect so I had to install the correct package and change the code to reflect that.
My tests run to completion but do nothing apart from creating the database. I then added the code to insert some student records and that also works correctly. I was only able to verify the success by running the sqlite3 program from a terminal window.
So for someone with very little knowledge of UWP, .NET and C# This article will not really help, as there are too many things in it which are wrong and/or missing.
[edit]
Adding a working solution based (loosely) on the original article.
1. Create a new UWP Blank page application in Visual Studio.
2. Replace the content of MainPage.xaml and MainPage.xaml.cs with the relevant parts below.
3. Add a new class named Students, and replace the text with the content of Students.cs below.
4. From the Visual Studio menu tabs Select Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution.
5. Use the "Browse" tab and search for "SQLite.Core.UAP" and install it to the project.
6. Search for "sqlite-net-pcl" and install that to the project.
If you have done that all correctly it should now build and you can run it by clicking <Ctrl+F5>.
MainPage.xaml
<Page
x:Class="Students.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Students"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<Style x:Name="ColumnItemBorder" TargetType="Border">
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="5, 0, 5, 0" />
</Style>
</Page.Resources>
<Grid Margin="5, 15, 5, 5">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<CommandBar Grid.Row="0">
<AppBarButton x:Name="init" Icon="NewWindow" Label="New" ToolTipService.ToolTip="Initialize" Click="create_Click"/>
<AppBarButton x:Name="add" Icon="Add" Label="Add" ToolTipService.ToolTip="Add" Click="insert_Click" />
<AppBarButton x:Name="read" Icon="ViewAll" ToolTipService.ToolTip="View all" Label="Read All" Click="read_Click"/>
<AppBarButton x:Name="update" Icon="Edit" ToolTipService.ToolTip="Update" Label="Update" Click="update_Click" />
</CommandBar>
<ListView x:Name="allstudents" HorizontalAlignment="Stretch" Grid.Row="1">
<ListView.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="120" />
</Grid.ColumnDefinitions>
<TextBlock Margin="15 0 0 0" Grid.Row="0" Grid.Column="0" Foreground="#ff0000" Text="Id" />
<TextBlock Margin="15 0 15 0" Grid.Row="0" Grid.Column="1" Foreground="#ff0000" Text="Name" />
<TextBlock Margin="15 0 15 0" Grid.Row="0" Grid.Column="2" Foreground="#ff0000" Text="Address" />
<TextBlock Margin="15 0 15 0" Grid.Row="0" Grid.Column="3" Foreground="#ff0000" Text="Mobile" />
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="120" />
</Grid.ColumnDefinitions>
<TextBlock Margin="7 0 0 0" Grid.Row="0" Grid.Column="0" Foreground="DarkBlue" Text="{Binding Id}"/>
<TextBlock Margin="7 0 15 0" Grid.Row="0" Grid.Column="1" Foreground="DarkBlue" Text="{Binding Name}" />
<TextBlock Margin="7 0 15 0" Grid.Row="0" Grid.Column="2" Foreground="DarkBlue" Text="{Binding Address}" />
<TextBlock Margin="7 0 15 0" Grid.Row="0" Grid.Column="3" Foreground="DarkBlue" Text="{Binding Mobile}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Xml.Linq;
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;
namespace Students
{
public sealed partial class MainPage : Page
{
Students students;
string dbname = "Studentdb.sqlite";
public MainPage()
{
this.InitializeComponent();
students = new Students();
}
private void create_Click(object sender, RoutedEventArgs e)
{
students.Initialize(dbname, true);
}
private void insert_Click(object sender, RoutedEventArgs e)
{
Student[] newstudents = {
new Student("Harold", "LONDON", "07966-513229"),
new Student("Sadie", "GLASGOW", "07981-277438"),
new Student("David", "NEW YORK", "+1-431-7438"),
new Student("Aristotle", "ATHENS", "+30-21-1234567"),
new Student("Carlo", "ROME", "+39-3987654321")
};
foreach (Student student in newstudents)
{
students.Add(student);
}
}
private void read_Click(object sender, RoutedEventArgs e)
{
List<Student> studentlist = students.ReadAll();
ObservableCollection<Student> studentCollection = new ObservableCollection<Student>(studentlist);
allstudents.BorderThickness = new Thickness(3);
allstudents.BorderBrush = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Black);
allstudents.ItemsSource = studentCollection;
}
private void update_Click(object sender, RoutedEventArgs e)
{
students.Update(3, null, "LOS ANGELES", "+1-345-7811");
}
}
}
Students.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace Students
{
internal class Students
{
string sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Studentdb.sqlite");
public Students()
{
}
public void Initialize(string database, bool create = false)
{
sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, database);
if (create)
{
using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(sqlpath))
{
connection.DropTable<Student>();
connection.CreateTable<Student>();
}
}
}
public void Add(Student student)
{
using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(sqlpath))
{
connection.RunInTransaction(() =>
{
connection.Insert(student);
});
}
}
public void Update(int studentid, string name, string address, string mobile)
{
using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(sqlpath))
{
var existingstudent = connection.Query<Student>("SELECT * FROM Student WHERE Id =\"" + studentid + "\"").FirstOrDefault();
if (existingstudent != null)
{
if (name != null)
existingstudent.Name = name;
if (address != null)
existingstudent.Address = address;
if (mobile != null)
existingstudent.Mobile = mobile;
connection.RunInTransaction(() =>
{
connection.Update(existingstudent);
});
}
}
}
public Student Read(int studentid)
{
using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(sqlpath))
{
var existingstudent = connection.Query<Student>("SELECT * FROM Student WHERE Id =" + studentid).FirstOrDefault();
return existingstudent;
}
}
public List<Student> ReadAll()
{
List<Student> studentList = null;
using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(sqlpath))
{
studentList = connection.Table<Student>().ToList<Student>();
}
return studentList;
}
public void DeleteContact(int Id)
{
using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(sqlpath))
{
var existingstudent = Read(Id);
if (existingstudent != null)
{
connection.RunInTransaction(() =>
{
connection.Delete(existingstudent);
});
}
}
}
}
internal class Student
{
[SQLite.PrimaryKey, SQLite.AutoIncrement]
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
public string Address
{
get;
set;
}
public string Mobile
{
get;
set;
}
public Student()
{ }
public Student(string name, string address, string mobile)
{
Name = name;
Address = address;
Mobile = mobile;
}
}
}
[edit]