You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.8 KiB
C#

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace DAL
{
public class DBHelperMySQL : DalInterface
{
private string connectionString = "";
public void CreateConnectionStringSql(string strConnectionString)
{
this.connectionString = strConnectionString;
}
public int ExecuteSql(string SQLString)
{
int num2;
using (MySqlConnection connection = new MySqlConnection(this.connectionString))
{
MySqlCommand command = new MySqlCommand(SQLString, connection);
command.CommandTimeout = 360;
try
{
connection.Open();
return command.ExecuteNonQuery();
}
catch (MySqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return num2;
}
public int ExecuteSql(string SQLString, params IDataParameter[] cmdParms)
{
int num2;
using (MySqlConnection connection = new MySqlConnection(this.connectionString))
{
MySqlCommand command = new MySqlCommand();
try
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
command.Connection = connection;
command.CommandTimeout = 360;
command.CommandText = SQLString;
command.CommandType = CommandType.Text;
if (cmdParms != null)
{
foreach (MySqlParameter parameter in cmdParms)
{
if (((parameter.Direction == ParameterDirection.InputOutput) || (parameter.Direction == ParameterDirection.Input)) && (parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
command.Parameters.Add(parameter);
}
}
int num = command.ExecuteNonQuery();
command.Parameters.Clear();
return num;
}
catch (MySqlException exception)
{
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return num2;
}
object DalInterface.GetSingle(string SQLString)
{
object obj3;
using (MySqlConnection connection = new MySqlConnection(this.connectionString))
{
MySqlCommand command = new MySqlCommand(SQLString, connection);
command.CommandTimeout = 360;
try
{
connection.Open();
object objA = command.ExecuteScalar();
if (object.Equals(objA, null) || object.Equals(objA, DBNull.Value))
{
return null;
}
return objA;
}
catch (MySqlException exception)
{
connection.Close();
throw exception;
}
finally
{
if (command != null)
{
command.Dispose();
}
}
}
return obj3;
}
DataSet DalInterface.Query(string SQLString)
{
using (MySqlConnection connection = new MySqlConnection(this.connectionString))
{
DataSet dataSet = new DataSet();
try
{
connection.Open();
MySqlDataAdapter sda = new MySqlDataAdapter(SQLString, connection);
sda.SelectCommand.CommandTimeout = 600;
sda.Fill(dataSet, "ds");
// new SqlDataAdapter(SQLString, connection).Fill
}
catch (MySqlException exception)
{
throw new Exception(exception.Message);
}
return dataSet;
}
}
}
}