Exemplo n.º 1
0
 /// <summary>
 /// Выполняет запрос SQL
 /// </summary>
 /// <param name="query"> запрос SQL</param>
 public static void QuerySQL(string query)
 {
     try
     {
         SqlCommand sqlComm = new SqlCommand();
         sqlComm             = mySqlConnection.CreateCommand();
         sqlComm.CommandText = query;
         mySqlConnection.Open();
         sqlComm.ExecuteNonQuery();
         mySqlConnection.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK);
         Log.Write(ex, "Ошибка  при выполнения запроса !!!");
         ConnectionStringDataBase.Delete();
         Environment.Exit(0);
         throw ex;
     }
     finally
     {
         if (mySqlConnection != null && mySqlConnection.State != ConnectionState.Closed)
         {
             mySqlConnection.Dispose();
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Метод принимает запроси возвращает таблицу DataTable
 /// </summary>
 /// <param name="query">запрос Sql</param>
 /// <returns>DateTable</returns>
 public static DataTable SelectToDateTable(string query)
 {
     try
     {
         SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
         mySqlCommand.CommandText = query;
         SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
         mySqlDataAdapter.SelectCommand = mySqlCommand;
         DataSet myDataSet = new DataSet();
         mySqlConnection.Open();
         mySqlDataAdapter.Fill(myDataSet, "table");
         mySqlConnection.Close();
         DataTable myDataTable = myDataSet.Tables["table"];
         return(myDataTable);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK);
         Log.Write(ex, "Ошибка  при выполнения запроса !!! ");
         ConnectionStringDataBase.Delete();
         Environment.Exit(0);
         throw ex;
     }
     finally
     {
         if (mySqlConnection != null && mySqlConnection.State != ConnectionState.Closed)
         {
             mySqlConnection.Dispose();
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///  Проверка подключения к БД
 /// </summary>
 /// <returns></returns>
 public static bool CheckConnection()
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(ConnectionStringDataBase.Read()))
         {
             int dircount = 0;
             connection.Open();
             SqlCommand cmd = new SqlCommand("SELECT count(*) FROM sys.Tables", connection);
             using (SqlDataReader reader = cmd.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     dircount = Convert.ToInt32(reader[0]);
                 }
             }
             if (dircount > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Возвращает строку подключения
 /// </summary>
 /// <returns>string </returns>
 public static string ConnectionString()
 {
     try
     {
         ConfigTxt config = new ConfigTxt();
         return(ConnectionStringDataBase.Read());
     }
     catch (Exception ex)
     {
         Log.Write(ex, " - Ошибкав с троке подключения !!!");
         throw ex;
     }
 }