6. Insert Query
INSERT INTO table_name
VALUES (value1, value2 , value3 …);
OR
INSERT INTO table_name
(column1, column2, column3 ….)
VALUES (value1, value2 , value3 …);
7. Select query
SELECT column_name, column_name2
FROM table_name
WHERE column_name operator value;
OR
SELECT *
FROM table_name
WHERE column_name operator value;
8. Operators
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than
<= Less than
LIKE Search for pattern
12. Step 1
First press tools then open extensions and updates, make sure these
2 extensions are available.
13. Step 2
Then from solution explorer right
click on references from windows 8.1
part then select add reference.
14. Step 3
After you open reference manager in windows phone select this.
15. Step 4
Then from solution explorer right
click on references from windows
8.1 part then select add reference.
16. Step 5
After you open reference manager in windows phone select this.
17. Step 6
You will notice these warnings in
windows and windows phone
18. Step 7
To solve this warnings open
configuration manager from the
Debug in the top bar of visual
studio.
19. Step 8
Right click on the project from solution and explorer then open
“manage nugget packages” and search for sqlite-net then install.
20. Step 9
To make sure every thing is going
right you`ll notice appearance of
this 2 classes in windows and
windows phone part.
21. Connect your database with C#
Create Database.
Check existence of database.
Create Table , Create using database connection.
Add record(s) to your table
Select record from your table
Remove record from your table
Update record from your table
Drop table
23. Table
We start defining the class that
represent the table row ->
Then add the table
to the database
24. Add a record to a table
Add one record. Add more than one record
25. Select record from your table
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("people.db");
var cityUsers = await conn.QueryAsync<User>(
"SELECT * FROM Users WHERE Name = ?", new object[] { textbox1.Text
});
foreach (var user in cityUsers)
{
UserList.ItemsSource = cityUsers;
}
26. Select all records
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("people.db");
bool dbExist = await CheckDbAsync("people.db");
if (!dbExist)
{
await CreateDataBase();
}
var query = conn.Table<User>();
users = await query.ToListAsync();
UserList.ItemsSource = users;
27. Delete Record
private void Button_Click_5(object sender, RoutedEventArgs e)
{
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path,
"people.db");
using (var db = new SQLite.SQLiteConnection(dbPath))
{ try
{ db.Execute("DELETE FROM Users WHERE Name = ?", textbox1.Text); }
catch (Exception ex)
{ // EXCEPTION HANDLING }}}
28. Update Record
private void Button_Click_6(object sender, RoutedEventArgs e)
{
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path,
"people.db");
using (var db = new SQLite.SQLiteConnection(dbPath))
{ try
{ db.Execute("UPDATE Users SET Name = ? WHERE Name = ?", textbox2.Text,textbox1.Text);
}
catch (Exception ex)
{ // EXCEPTION HANDLING }}}