96 lines
2.3 KiB
C#
96 lines
2.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;
|
|
|
|
namespace DatabaseClient
|
|
{
|
|
public class MysqlClient
|
|
{
|
|
|
|
public static bool ExecQuerySQL(string sql, string ConnectStr, out string err)
|
|
{
|
|
// lock (losk1) {
|
|
bool success = false;
|
|
err = "";
|
|
using (MySqlConnection conn = new MySqlConnection(ConnectStr))
|
|
{
|
|
try
|
|
{
|
|
conn.Open();
|
|
|
|
MySqlCommand command = new MySqlCommand(sql, conn);
|
|
command.ExecuteNonQuery();
|
|
success = true;
|
|
}
|
|
catch (Exception er)
|
|
{
|
|
err = er.Message;
|
|
}
|
|
finally
|
|
{
|
|
if (conn != null)
|
|
{
|
|
conn.Close();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool ExecQueryDataTable(string sql, string ConnectStr,out DataTable dt, out string err)
|
|
{
|
|
bool success = false;
|
|
err = "";
|
|
dt = null;
|
|
using (MySqlConnection conn = new MySqlConnection(ConnectStr))
|
|
{
|
|
try
|
|
{
|
|
conn.Open();
|
|
|
|
MySqlCommand command = new MySqlCommand(sql, conn);
|
|
MySqlDataAdapter da = new MySqlDataAdapter(command);
|
|
DataSet ds = new DataSet();
|
|
da.Fill(ds);
|
|
|
|
if (ds.Tables.Count > 0)
|
|
{
|
|
dt = ds.Tables[0];
|
|
}
|
|
success = true;
|
|
}
|
|
catch (Exception er)
|
|
{
|
|
err = er.Message;
|
|
}
|
|
finally
|
|
{
|
|
if (conn != null)
|
|
{
|
|
conn.Close();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|