FarmMapsApiClient/FarmmapsBulkSatDownload/Models/DB.cs

48 lines
1.2 KiB
C#
Raw Permalink Normal View History

2021-05-18 16:19:28 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using Npgsql;
namespace FarmmapsBulkSatDownload.Models
2021-05-18 16:19:28 +00:00
{
public class DB
{
public string Database;
public string User;
public string Password;
public string Host;
public string GetConnectionString()
{
NpgsqlConnectionStringBuilder sb = new NpgsqlConnectionStringBuilder();
sb.Database = Database;
sb.Host = Host;
sb.Username = User;
sb.Password = Password;
sb.Port = 5432;
return sb.ConnectionString;
}
public int ExecuteNonQuery(string sql)
{
using (NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString()))
{
conn.Open();
NpgsqlCommand command = conn.CreateCommand();
command.CommandText = sql;
int r = command.ExecuteNonQuery();
return r;
}
}
public NpgsqlConnection CreateConnection()
{
NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString());
conn.Open();
return conn;
}
}
}