Last active
May 19, 2025 10:06
-
-
Save JJack55on/762a2bf184be860746fcaaa4b455ab9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System.Data; | |
using Npgsql; | |
namespace DbTusk; | |
class Program | |
{ | |
private const string connString = | |
" "; | |
static void Main(string[] args) | |
{ | |
var tables = new List<Tables>(); | |
var connection = new NpgsqlConnection(connString); | |
try | |
{ | |
var query = @"select * from ""EZ_tables"".""Teachers""; | |
select * from ""EZ_tables"".""Students""; | |
select * from ""EZ_tables"".""Subjects"";"; | |
var command = new NpgsqlCommand(query, connection); | |
connection.Open(); | |
var reader = command.ExecuteReader(); | |
while (reader.Read()) | |
{ | |
tables.Add(new Tables | |
{ | |
TeacherName = reader.GetString("Teacher"), | |
StudentName = reader.GetString("Student"), | |
SubjectName = reader.GetString("Subject") | |
}); | |
} | |
reader.Close(); | |
command.Dispose(); | |
tables.ForEach(select => Console.WriteLine($" {select.SubjectName} : {select.TeacherName} : {select.StudentName}")); | |
} | |
finally | |
{ | |
if (connection.State == ConnectionState.Open) | |
connection.Close(); | |
} | |
} | |
public class Tables | |
{ | |
public int Id { get; init; } | |
public string TeacherName { get; init; } = default!; | |
public string StudentName { get; init; } = default!; | |
public string SubjectName { get; init; } = default!; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment