Programming C#

SQLite

Database

Create Table

CREATE TABLE Category(
	CategoryId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
	CategoryName VARCHAR(64) NOT NULL
);

Insert Data

INSERT INTO Category (CategoryName) VALUES ('Laptop'), ('Mouse');
COMMIT;

Code C#

Add Package from nuget Npgsql

dotnet add package Npgsql

Connect C# to Postgres SQL

using System.Data;
using System.Data.SQLite;
IDbConnection connection = new SQLiteConnection(@"Data Source=D:\SQL\EStore.db");
connection.Open();
IDbCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Category";
IDataReader reader = command.ExecuteReader();
while(reader.Read()){
    System.Console.WriteLine(reader.GetName(0));
    System.Console.WriteLine(reader.GetInt32(0));
    System.Console.WriteLine(reader.GetString(1));
    //System.Console.WriteLine(reader.GetName(1));
}
reader.Dispose();
command.Dispose();
connection.Dispose();