40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using Npgsql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WebsiteForPlacingAds
|
|
{
|
|
public abstract class AbstractDatabase
|
|
{
|
|
private NpgsqlConnection connection;
|
|
|
|
public AbstractDatabase(string connectionString)
|
|
{
|
|
connection = new NpgsqlConnection(connectionString);
|
|
}
|
|
|
|
protected DataTable ExecuteQuery(string query)
|
|
{
|
|
connection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(query, connection);
|
|
NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(command);
|
|
DataTable result = new DataTable();
|
|
adapter.Fill(result);
|
|
connection.Close();
|
|
return result;
|
|
}
|
|
|
|
protected void ExecuteNonQuery(string query)
|
|
{
|
|
connection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(query, connection);
|
|
command.ExecuteNonQuery();
|
|
connection.Close();
|
|
}
|
|
}
|
|
}
|