KalkulatorISP-31rrrrr/source/repos/WindowsFormsApp19/Class1.cs
2025-11-11 14:18:33 +04:00

41 lines
1.3 KiB
C#

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp19
{
internal class DbConnection
{
public static DataTable select(string sql)
{
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
builder.Server = "cfif31.ru";
builder.Port = 3306;
builder.Database = "ISPr24-57_GrivaAO_MasterPol";
builder.UserID = "ISPr24-57_GrivaAO";
builder.Password = "ISPr24-57_GrivaAO";
MySqlConnection connect = new MySqlConnection(builder.ConnectionString);
try
{
connect.Open();
MySqlCommand command = new MySqlCommand(sql, connect);
MySqlDataReader reader = command.ExecuteReader();
DataTable table = new DataTable();
table.Load(reader);
return table;
}
catch (Exception e)
{
MessageBox.Show("При выполнении запроса произошла ошибка! " + e.Message);
return null;
}
}
}
}