init: CATL电池线SCADA首次入库
This commit is contained in:
95
DT_SCADA/Core/MysqlClient.cs
Normal file
95
DT_SCADA/Core/MysqlClient.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user