Пример #1
0
        private void ExecuteDBOperations(string stringSQL, string msg)
        {
            var dbConnection = new DbConnection();

            using (_SqlConn = new SqlConnection(dbConnection.PrepareStringConnection()))
            {
                _Comm = _SqlConn.CreateCommand();
                _SqlConn.Open();

                _Comm.CommandText = stringSQL;
                _Comm.CommandType = CommandType.Text;
                _Comm.Parameters.Clear();
                try
                {
                    int n = _Comm.ExecuteNonQuery();
                    if (n > 0)
                    {
                        MessageBox.Show(msg);
                        LoadDataManagementGrid(homeWork.PrepareSQLForDataManagementGrid());
                        ResetAll();
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("UNIQUE KEY constraint"))
                    {
                        MessageBox.Show("Row already existent");
                    }
                    else
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }