Restructure data access layer/data layer

This commit is contained in:
Aaron Po
2026-01-11 23:36:26 -05:00
parent 8d6b903aa7
commit 372aac897a
17 changed files with 457 additions and 256 deletions

View File

@@ -0,0 +1,55 @@
using System;
using System.Data;
using Microsoft.Data.SqlClient;
namespace DataAccessLayer.Sql
{
public class DatabaseHelper
{
private readonly string _connectionString;
public DatabaseHelper(string connectionString)
{
_connectionString = connectionString;
}
public void ExecuteRawSql(string query)
{
try
{
using (
SqlConnection connection = new SqlConnection(
_connectionString
)
)
{
connection.Open();
using (
SqlCommand command = new SqlCommand(query, connection)
)
{
command.CommandType = CommandType.Text;
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine(
$"{reader.GetName(i)}: {reader.GetValue(i)}"
);
}
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
}