85 lines
1.7 KiB
C#
85 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ScaBox30.Controller
|
|
{
|
|
internal class DbController
|
|
{
|
|
private string _path;
|
|
private OleDbConnection _connection;
|
|
private OleDbCommand _command;
|
|
private OleDbDataReader _reader;
|
|
|
|
|
|
|
|
public void SetWorkingDb(string path)
|
|
{
|
|
_path = path;
|
|
}
|
|
|
|
|
|
public void Open()
|
|
{
|
|
_connection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + _path);
|
|
try
|
|
{
|
|
_connection.Open();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
|
|
public void Close()
|
|
{
|
|
try
|
|
{
|
|
_connection.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
|
|
public OleDbDataReader Query(string query)
|
|
{
|
|
try
|
|
{
|
|
_command = new OleDbCommand(query, _connection);
|
|
_reader = _command.ExecuteReader();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
return _reader;
|
|
}
|
|
|
|
|
|
public void InsertQuery(String query)
|
|
{
|
|
try
|
|
{
|
|
_command = new OleDbCommand(query, _connection);
|
|
_command.ExecuteNonQuery();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|