-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
51 lines (38 loc) · 1.74 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace CodeGitz
{
internal class Program
{
static void Main(string[] args)
{
// Create The "posts" Table
CreateTable();
// Insert Records Into "posts"
InsertData();
// Display Data Entries
ReadTable();
}
static void CreateTable()
{
// Create a Table With Columns Id, Name and URL Where ID is The Primary Key
var CreateStatement = @"CREATE TABLE IF NOT EXISTS posts (Id INTEGER NOT NULL UNIQUE, Name TEXT NOT NULL,Url TEXT NOT NULL,PRIMARY KEY(Id AUTOINCREMENT))";
// Call the CreateTable Function From SQLiteOps.cs
SQLiteOps.CreateTable(CreateStatement);
}
static void InsertData()
{
List<String> InsertStatements = new();
InsertStatements.Add("INSERT INTO posts (Name,Url) VALUES ('C# - Debugging StackOverflow Exception','https://codegitz.com/c-debugging-stackoverflow-exception/');");
InsertStatements.Add("INSERT INTO posts (Name,Url) VALUES ('C# - How To Convert JSON Array To List?','https://codegitz.com/c-how-to-convert-json-array-to-list/');");
InsertStatements.Add("INSERT INTO posts (Name,Url) VALUES ('C# - How To Implement Shortcut Keys in Winforms?','https://codegitz.com/how-to-implement-shortcut-keys-in-winforms/');");
SQLiteOps.InsertRecords(InsertStatements);
}
static void ReadTable()
{
List<Posts> CodeGitzPosts = SQLiteOps.ReadTable();
foreach (Posts Post in CodeGitzPosts)
{
Console.WriteLine($"Post ID: {Post.Id} \nPost Title: {Post.Name} \nPost URL: {Post.Url}\n\n");
}
}
}
}